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

Re: /* compiler workaround */ - what was the issue?

From
Duy Nguyen <pclouds@gmail.com>
Date
May 6, 2016, 10:17 UTC
Message-ID
<CACsJy8CBuU8H8r_f4KsnLkhLtfRv0nDo4hGS31LVn0e1Y_3OAQ@mail.gmail.com>
In-Reply-To
<xmqqtwic9o88.fsf@gitster.mtv.corp.google.com>
On Fri, May 6, 2016 at 4:41 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
> "Philip Oakley" <philipoakley@iee.org> writes:
>
>>     int saved_namelen = saved_namelen; /* compiler workaround */
>>
>> Which then becomes an MSVC compile warning C4700: uninitialized local
>> variable.
>>
>> I'm wondering what was the compiler workaround being referred to? i.e. why
>> does it need that tweak? There's no mention of the reason in the commit
>> message.
>
> That was a fairly well-known workaround for GCC that issues a false
> warning that variable is used before initialized.  I thought we
> stopped using it several years ago in new code after doing a bulk
> sanitizing

I guess that's 803a777 (cat-file: Fix an gcc -Wuninitialized warning - 2013-03-26) and more commits around that time. The split-index commit is in 2014. I must have missed the trend.

> (I think the new recommended workaround was to initialise
> such a variable to the nil value like '0' for integers).

Yep. First Jeff removed the " = xxx" part from "xxx = xxx" then Ramsay added the " = NULL" back. So we probably just do "int saved_namelen = 0;" in this case.

-- 
Duy
Previous: Junio C HamanoNext: Philip Oakley
Message 3 of 15 in “/* compiler workaround */ - what was the issue?”
  1. Philip OakleyMay 5, 2016
  2. Junio C HamanoMay 5, 2016
  3. Duy NguyenMay 6, 2016
  4. Philip OakleyMay 6, 2016
  5. Ramsay JonesMay 6, 2016
  6. Philip OakleyMay 6, 2016
  7. Junio C HamanoMay 6, 2016
  8. Marc BranchaudMay 6, 2016
  9. Junio C HamanoMay 6, 2016
  10. Stefan BellerMay 6, 2016
  11. Philip OakleyMay 9, 2016
  12. Randall S. BeckerMay 9, 2016
  13. Marc BranchaudMay 6, 2016
  14. Ramsay JonesMay 6, 2016
  15. Ramsay JonesMay 6, 2016

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.