bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#17667: [PATCH] df: Initialize a variable to squash a compiler warnin


From: Pádraig Brady
Subject: bug#17667: [PATCH] df: Initialize a variable to squash a compiler warning
Date: Mon, 02 Jun 2014 20:22:19 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 06/02/2014 09:09 AM, Ben Walton wrote:
> * src/df.c: get_dev - With strict error checking, gcc complained that
>             v may have been used prior to initialization. To avoid
>             this, initialize to NULL.
> 
> Signed-off-by: Ben Walton <address@hidden>
> ---
>  src/df.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/df.c b/src/df.c
> index 01ecca6..059c958 100644
> --- a/src/df.c
> +++ b/src/df.c
> @@ -924,7 +924,7 @@ get_dev (char const *disk, char const *mount_point, char 
> const* file,
>        char buf[LONGEST_HUMAN_READABLE + 2];
>        char *cell;
>  
> -      struct field_values_t *v;
> +      struct field_values_t *v = NULL;
>        switch (columns[col]->field_type)
>          {
>          case BLOCK_FLD:
> @@ -934,7 +934,7 @@ get_dev (char const *disk, char const *mount_point, char 
> const* file,
>            v = &inode_values;
>            break;
>          case OTHER_FLD:
> -          v = NULL;
> +          /* Rely on NULL initialization. */
>            break;
>          default:
>            assert (!"bad field_type");

This is because assert() is not declared __noreturn__ on Solaris 10.
That can be an important admonition for a compiler
so I'm wondering should be detect this and provide a __noreturn__ wrapper.

Anyway what I don't want to do is change the current logic
to avoid such bogus warnings. What we could do here
is to tweak the assert path only to avoid the warning as follows.
OK to push the following instead in your name?

thanks,
Pádraig.

diff --git a/src/df.c b/src/df.c
index 82b0c5f..c08ad97 100644
--- a/src/df.c
+++ b/src/df.c
@@ -953,6 +953,7 @@ get_dev (char const *disk, char const *mount_point, char con
           v = NULL;
           break;
         default:
+          v = NULL; /* avoid warnings where assert() is not __noreturn__.  */
           assert (!"bad field_type");
         }







reply via email to

[Prev in Thread] Current Thread [Next in Thread]