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

Re: possible code error at run_command.c

From
Erik Faye-Lund <kusmabite@googlemail.com>
Date
Dec 21, 2009, 09:08 UTC
Message-ID
<40aa078e0912210108y4ea67dbfs2025bae20bdfb381@mail.gmail.com>
In-Reply-To
<4B2F3732.6030903@viscovery.net>
On Mon, Dec 21, 2009 at 9:52 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 34 quoted lines
> Erik Faye-Lund schrieb:
>> On Mon, Dec 21, 2009 at 9:30 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>> Frank Li schrieb:
>>>> Maybe some excute path miss initialized it. Otherwise compiler will
>>>> not report warning.
>>> LOOK AT THE CODE. There is no such code path.
>>>
>>
>> That's odd.
>
> Only if Frank did the homework and removed the initialization from
>
>        int failed_errno = failed_errno;
>
>> I agree, there isn't such a code path. But this is the
>> first time I've ever seen this MSVC-feature turn up false positives,
>> which puzzles me.
>
> This line will trigger the check. It initializes failed_errno with itself,
> which is still uninitialized at this time.
>
> Note that we have more definitions of this kind:
>
> $ git grep -E ' ([a-zA-Z_][a-zA-Z_0-9]*) = \1[;,]' *.c
> builtin-rev-list.c:             int reaches = reaches, all = all;
> match-trees.c:          unsigned mode1 = mode1;
> match-trees.c:          unsigned mode2 = mode2;
> run-command.c:  int failed_errno = failed_errno;
> transport.c:            int cmp = cmp, len;
> wt-status.c:    int status = status;
>
> -- Hannes
>
>

Right, I didn't think of that. Since that is the case, I'd say disabling run-time checks is perfectly sane.

That being said, it might make sense for MSVC people to be able to have this feature turned on so they can easier find REAL programmer-errors. But I guess removing the self-assignments makes trouble for non-MSVC people.

Perhaps some of these warnings could be avoided in a "safer" way? IMO, assigning variables to themselves like this is a bit fishy, as it effectively hides uninitialized-use warnings for the entire lifetime of that variable. Sure, the programmer who did that probably knows what he or she does -- but they can't possibly know what people will do in the future. If we could somehow turn these (really few) occasions into something that produces reliable warnings on uninitialized variables, I think we might be able to catch some bugs earlier.

-- 
Erik "kusma" Faye-Lund
Previous: Johannes SixtNext: Frank Li
Message 10 of 11 in “possible code error at run_command.c”
  1. Frank LiDec 21, 2009
  2. Wincent ColaiutaDec 21, 2009
  3. Johannes SixtDec 21, 2009
  4. Frank LiDec 21, 2009
  5. Johannes SixtDec 21, 2009
  6. Frank LiDec 21, 2009
  7. Johannes SixtDec 21, 2009
  8. Erik Faye-LundDec 21, 2009
  9. Johannes SixtDec 21, 2009
  10. Erik Faye-LundDec 21, 2009
  11. Frank LiDec 21, 2009

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.