Re: [PATCH v5 02/16] reftable: fix resource leak in block.c error path
- From
René Scharfe <l.s.r@web.de>
- Date
- Jan 12, 2022, 14:03 UTC
- Message-ID
- <6993c156-4df1-198f-5ce0-781ba13d5dd2@web.de>
- In-Reply-To
- <CAFQ2z_OFK77TC605GqM2Lw1Lf21fyF2cVKkGVrXO6TP6zcp+mw@mail.gmail.com>
Am 12.01.22 um 12:58 schrieb Han-Wen Nienhuys:
Show 22 quoted lines
> On Fri, Dec 24, 2021 at 5:16 AM Junio C Hamano <gitster@pobox.com> wrote:
>> Once you
>> initialize at the declaration with "less meaningful" value (like
>> zero initialization), the tools won't be able to tell when the code
>> uses that variable "uninitialized" (because the assignment was
>> skipped by a bug), since it appears to always be initialied to them.
>
> Which tools are these? When I add
>
> static void test_memcpy(void)
> {
> uint32_t dest;
> char not_init[200];
> int i;
> memcpy(&dest, not_init, sizeof(dest));
>
> for (i = 0 ; i < 10; i++)
> not_init[i] = rand() % 255 + 1;
> printf("%d", (int) strlen(not_init));
> }
>
> to the C code, it compiles cleanly if I do "make DEVELOPER=1".https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html says about -Wuninitialized:
"Note that there may be no warning about a variable that is used only
to compute a value that itself is never used, because such
computations may be deleted by data flow analysis before the
warnings are printed."And indeed, dest is not used above. But even if we change the funtion to use dest by returning it, GCC versions 9.1 and higher don't warn about the use of the uninitialized buffer. GCC 4.7.1 to 8.5 do warn, though: https://godbolt.org/z/zYz9KvPdK
René