git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix compiler warning by properly initialize failed_errno
@ 2009-08-02 19:34 David Soria Parra
  2009-08-04  6:07 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: David Soria Parra @ 2009-08-02 19:34 UTC (permalink / raw)
  To: git; +Cc: David Soria Parra

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
-- 
1.6.4.212.g4719.dirty

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix compiler warning by properly initialize failed_errno
  2009-08-02 19:34 [PATCH] Fix compiler warning by properly initialize failed_errno David Soria Parra
@ 2009-08-04  6:07 ` Junio C Hamano
  2009-08-04  9:27   ` sn_
  2009-08-04 18:51   ` Johannes Sixt
  0 siblings, 2 replies; 6+ messages in thread
From: Junio C Hamano @ 2009-08-04  6:07 UTC (permalink / raw)
  To: David Soria Parra; +Cc: git, David Soria Parra, Johannes Sixt

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.

The potentially uninitialized use your compiler is worried about is inside
if (cmd->pid < 0) after #ifdef/#else/#endif.

 (1) if not on MINGW32, we would have already assigned to failed_errno
     after fork() returns negative value to cmd->pid;

 (2) if on MINGW32, we would have assigned to failed_errno unconditionally
     after calling mingw_spawnvpe().

so its worry is unfounded.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix compiler warning by properly initialize failed_errno
  2009-08-04  6:07 ` Junio C Hamano
@ 2009-08-04  9:27   ` sn_
  2009-08-04 22:22     ` Junio C Hamano
  2009-08-04 18:51   ` Johannes Sixt
  1 sibling, 1 reply; 6+ messages in thread
From: sn_ @ 2009-08-04  9:27 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: j6t, git


> The potentially uninitialized use your compiler is worried about is inside
> if (cmd->pid < 0) after #ifdef/#else/#endif.
> 
>  (1) if not on MINGW32, we would have already assigned to failed_errno
>      after fork() returns negative value to cmd->pid;
> 
>  (2) if on MINGW32, we would have assigned to failed_errno unconditionally
>      after calling mingw_spawnvpe().
> 
> so its worry is unfounded.

The worry is definatly unfounded, but I think it's still worth to apply the attached patch to get rid of the warning using the i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490) compiler. I sended a corrected version of the patch to the ml.

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix compiler warning by properly initialize failed_errno
  2009-08-04  6:07 ` Junio C Hamano
  2009-08-04  9:27   ` sn_
@ 2009-08-04 18:51   ` Johannes Sixt
  2009-08-04 19:09     ` Junio C Hamano
  1 sibling, 1 reply; 6+ messages in thread
From: Johannes Sixt @ 2009-08-04 18:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: David Soria Parra, git, David Soria Parra

Junio C Hamano schrieb:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix compiler warning by properly initialize failed_errno
  2009-08-04 18:51   ` Johannes Sixt
@ 2009-08-04 19:09     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2009-08-04 19:09 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: David Soria Parra, git, David Soria Parra

Johannes Sixt <j6t@kdbg.org> writes:

> Junio C Hamano schrieb:
>
>> 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.

It is not about optimization at all.  This is about documenting the fact
that we have audited and know that the use of this variable in the code
that follows is Ok.  Initializing to 0 gives a false impression that the
code may rely on that value, but in this case nobody will ever read that
zero before overwriting it with an assignment.

The compiler may optimize this out, but that is an insignificant (I agree
this is not a performance critical codepath) side effect.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Fix compiler warning by properly initialize failed_errno
  2009-08-04  9:27   ` sn_
@ 2009-08-04 22:22     ` Junio C Hamano
  0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2009-08-04 22:22 UTC (permalink / raw)
  To: sn_; +Cc: j6t, git

"sn_" <sn_@gmx.net> writes:

>> The potentially uninitialized use your compiler is worried about is inside
>> if (cmd->pid < 0) after #ifdef/#else/#endif.
>> 
>>  (1) if not on MINGW32, we would have already assigned to failed_errno
>>      after fork() returns negative value to cmd->pid;
>> 
>>  (2) if on MINGW32, we would have assigned to failed_errno unconditionally
>>      after calling mingw_spawnvpe().
>> 
>> so its worry is unfounded.
>
> The worry is definatly unfounded, but I think it's still worth to apply
> the attached patch to get rid of the warning using the
> i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
> compiler. I sended a corrected version of the patch to the ml.

Oh, there was no need for you to say "but..." and everything that followed.
I said "we should say ... instead" in my review comments, didn't I?  

We are obviously in agreement ;-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-08-04 22:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-02 19:34 [PATCH] Fix compiler warning by properly initialize failed_errno David Soria Parra
2009-08-04  6:07 ` Junio C Hamano
2009-08-04  9:27   ` sn_
2009-08-04 22:22     ` Junio C Hamano
2009-08-04 18:51   ` Johannes Sixt
2009-08-04 19:09     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).