git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix maybe-uninitialized warnings found by gcc 9 -flto

From
René Scharfe <l.s.r@web.de>
Date
Sep 5, 2019, 19:39 UTC
Message-ID
<8d90d803-8a4b-2656-550d-ccee5156b643@web.de>
In-Reply-To
<xmqqr24upmtm.fsf@gitster-ct.c.googlers.com>
Am 05.09.19 um 21:25 schrieb Junio C Hamano:
Show 28 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>> 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.

The loop count is either 1 or argv[1] interpreted as a number, i.e. it could be very high. Its body consists of an index load and writing a number to a file, though -- a strlen() call on the name of that file should go unnoticed amid that activity. (I didn't measure it, though.)

René
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 23 in “Fix maybe-uninitialized warnings found by gcc 9 -flto”
  1. Fix maybe-uninitialized warnings found by gcc 9 -fltoStephan Beyer, Sep 5, 2019
  2. René ScharfeSep 5, 2019
  3. Jeff KingSep 5, 2019
  4. René ScharfeSep 5, 2019
  5. Junio C HamanoSep 5, 2019
  6. René ScharfeSep 5, 2019
  7. Junio C HamanoSep 5, 2019
  8. Junio C HamanoSep 5, 2019
  9. Junio C HamanoSep 5, 2019
  10. Jeff KingSep 5, 2019
  11. Junio C HamanoSep 5, 2019
  12. Jeff KingSep 5, 2019
  13. 1/6 git-am: handle missing "author" when parsing commitJeff King, Sep 5, 2019
  14. 2/6 pack-objects: use object_id in packlist_alloc()Jeff King, Sep 5, 2019
  15. 3/6 bulk-checkin: zero-initialize hashfile_checkpointJeff King, Sep 5, 2019
  16. 4/6 diff-delta: set size out-parameter to 0 for NULL deltaJeff King, Sep 5, 2019
  17. Stephan BeyerSep 5, 2019
  18. Jeff KingSep 5, 2019
  19. Stephan BeyerSep 5, 2019
  20. Jeff KingSep 6, 2019
  21. 6/6 pack-objects: drop packlist index_pos optimizationJeff King, Sep 6, 2019
  22. 5/6 test-read-cache: drop namelen variableJeff King, Sep 5, 2019
  23. 6/6 pack-objects: drop packlist index_pos optimizationJeff King, Sep 5, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.