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

Re: [PATCH] Fix compiler warning by properly initialize failed_errno

From
Johannes Sixt <j6t@kdbg.org>
Date
Aug 4, 2009, 18:51 UTC
Message-ID
<4A78834C.20002@kdbg.org>
In-Reply-To
<7vmy6g6rj1.fsf@alter.siamese.dyndns.org>
Junio C Hamano schrieb:
Show 33 quoted lines
> David Soria Parra <sn_@gmx.net> writes:
> 
>> From: David Soria Parra <dsp@php.net>
>>
>> Initilize failed_error in start_command to avoid compiler warnings
>>
>> Signed-off-by: David Soria Parra <dsp@php.net>
>> ---
>>  run-command.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/run-command.c b/run-command.c
>> index dc09433..510349b 100644
>> --- a/run-command.c
>> +++ b/run-command.c
>> @@ -19,7 +19,7 @@ int start_command(struct child_process *cmd)
>>  {
>>  	int need_in, need_out, need_err;
>>  	int fdin[2], fdout[2], fderr[2];
>> -	int failed_errno;
>> +	int failed_errno = 0;
>>  
>>  	/*
>>  	 * In case of errors we must keep the promise to close FDs
> 
> We would want to be able to distinguish between a workaround for a
> compiler that is not clever/careful enough, and a necessary
> initialization.  In this particular case, it is the former, and we should
> say
> 
> 	int failed_errno = failed_errno;
> 
> instead.

Frankly, I prefer the initialization with 0; this is not a performance critical place and micro-optimization is not appropriate here.

(If this were C++ then I *know* that int x = x; is undefined behavior, strictly speaking; I don't know whether it is the same with C.)

Nevertheless, for both versions:
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes
Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 6 in “Fix compiler warning by properly initialize failed_errno”
  1. Fix compiler warning by properly initialize failed_errnoDavid Soria Parra, Aug 2, 2009
  2. Junio C HamanoAug 4, 2009
  3. sn_Aug 4, 2009
  4. Junio C HamanoAug 4, 2009
  5. Johannes SixtAug 4, 2009
  6. Junio C HamanoAug 4, 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.