Re: [PATCH] Fix maybe-uninitialized warnings found by gcc 9 -flto
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 5, 2019, 19:25 UTC
- Message-ID
- <xmqqr24upmtm.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <b4f53049-ff50-8143-1653-d321cce6421c@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 23 quoted lines
> Am 05.09.19 um 19:53 schrieb Jeff King:
>>>> int cmd__read_cache(int argc, const char **argv)
>>>> {
>>>> - int i, cnt = 1, namelen;
>>>> + int i, cnt = 1, namelen = 0;
>>
>> I actually saw this one the other day, because it triggered for me when
>> compiling with SANITIZE=address. AFAICT it's a false positive. "name" is
>> always NULL unless skip_prefix() returns true, in which case we always
>> set "namelen". And we only look at "namelen" if "name" is non-NULL.
>>
>> This one doesn't even require LTO, because skip_prefix() is an inline
>> function. I'm not sure why the compiler gets confused here.
>
> Yes, that's curious.
>
>> I don't mind
>> initializing namelen to 0 to silence it, though (we already set name to
>> NULL, so this would just match).
>
> Pushing the strlen() call into the loop and getting rid of namelen should
> work as well -- and I'd be surprised if this had a measurable performance
> impact.Yeah, we are making strlen() call on a constant "name" in a loop over argv[]. I do not think it matters in this case, either.