coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] df: fix use of uninitialized variable reported by valgrind


From: Bernhard Voelker
Subject: Re: [PATCH] df: fix use of uninitialized variable reported by valgrind
Date: Thu, 02 Apr 2015 11:10:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

On 04/02/2015 06:37 AM, Pádraig Brady wrote:
>  Conditional jump or move depends on uninitialised value(s)
>     at 0x40380C: get_field_values (df.c:840)
>     by 0x403E16: get_dev (df.c:994)
>     by 0x404D65: get_all_entries (df.c:1364)
>     by 0x405926: main (df.c:1714)
> 
> * src/df.c (get_dev): Initialize the fsu.fsu_bavail_top_bit_set
> member, when adding placeholder entries.
> ---
>  src/df.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/src/df.c b/src/df.c
> index 76a3e37..4eda393 100644
> --- a/src/df.c
> +++ b/src/df.c
> @@ -925,6 +925,7 @@ get_dev (char const *disk, char const *mount_point, char 
> const* file,
>              return;
>  
>            fstype = "-";
> +          fsu.fsu_bavail_top_bit_set = false;
>            fsu.fsu_blocksize = fsu.fsu_blocks = fsu.fsu_bfree =
>            fsu.fsu_bavail = fsu.fsu_files = fsu.fsu_ffree = UINTMAX_MAX;
>          }
> @@ -949,6 +950,7 @@ get_dev (char const *disk, char const *mount_point, char 
> const* file,
>                && (! dev_me->me_remote || ! me_remote))
>              {
>                fstype = "-";
> +              fsu.fsu_bavail_top_bit_set = false;
>                fsu.fsu_blocksize = fsu.fsu_blocks = fsu.fsu_bfree =
>                fsu.fsu_bavail = fsu.fsu_files = fsu.fsu_ffree = UINTMAX_MAX;
>              }
> 

Nice one, thanks!

Would you like to squash in another minor fix for non-freed memory?
Valgrind reports this if df is run with arguments:

--- a/src/df.c
+++ b/src/df.c
@@ -1711,6 +1711,8 @@ main (int argc, char **argv)
       for (i = optind; i < argc; ++i)
         if (argv[i])
           get_entry (argv[i], &stats[i - optind]);
+
+      IF_LINT (free (stats));
     }
   else
     get_all_entries ();


Have a nice day,
Berny



reply via email to

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