git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* possible code error at run_command.c
@ 2009-12-21  6:46 Frank Li
  2009-12-21  7:09 ` Wincent Colaiuta
  2009-12-21  7:18 ` Johannes Sixt
  0 siblings, 2 replies; 11+ messages in thread
From: Frank Li @ 2009-12-21  6:46 UTC (permalink / raw)
  To: git

int start_command(struct child_process *cmd)
{
	int need_in, need_out, need_err;
	int fdin[2], fdout[2], fderr[2];
	int failed_errno = failed_errno;

I have not found failed_errno as global variable.
failed_errno = failed_errno means nothing.

It is possible coding error and should be
int failed_errno= 0 or
failed_errno=errno.

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

* Re: possible code error at run_command.c
  2009-12-21  6:46 possible code error at run_command.c Frank Li
@ 2009-12-21  7:09 ` Wincent Colaiuta
  2009-12-21  7:18 ` Johannes Sixt
  1 sibling, 0 replies; 11+ messages in thread
From: Wincent Colaiuta @ 2009-12-21  7:09 UTC (permalink / raw)
  To: Frank Li; +Cc: git

El 21/12/2009, a las 07:46, Frank Li escribió:

> int start_command(struct child_process *cmd)
> {
> 	int need_in, need_out, need_err;
> 	int fdin[2], fdout[2], fderr[2];
> 	int failed_errno = failed_errno;
>
> I have not found failed_errno as global variable.
> failed_errno = failed_errno means nothing.
>
> It is possible coding error and should be
> int failed_errno= 0 or
> failed_errno=errno.

Via "git blame":

commit 5a7a3671b74c043216549b94a718da04cc3ffcd6
Author: David Soria Parra <dsp@php.net>
Date:   Tue Aug 4 11:28:40 2009 +0200

     run-command.c: squelch a "use before assignment" warning

     i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)  
compiler
     (and probably others) mistakenly thinks variable failed_errno is  
used
     before assigned.  Work it around by giving it a fake  
initialization.

     Signed-off-by: David Soria Parra <dsp@php.net>
     Signed-off-by: Junio C Hamano <gitster@pobox.com>


Cheers,
Wincent

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

* Re: possible code error at run_command.c
  2009-12-21  6:46 possible code error at run_command.c Frank Li
  2009-12-21  7:09 ` Wincent Colaiuta
@ 2009-12-21  7:18 ` Johannes Sixt
  2009-12-21  7:29   ` Frank Li
  1 sibling, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2009-12-21  7:18 UTC (permalink / raw)
  To: Frank Li; +Cc: git

Frank Li schrieb:
> int start_command(struct child_process *cmd)
> {
> 	int need_in, need_out, need_err;
> 	int fdin[2], fdout[2], fderr[2];
> 	int failed_errno = failed_errno;
> 
> I have not found failed_errno as global variable.
> failed_errno = failed_errno means nothing.

This is a commonly used idiom to avoid an (incorrect) compiler warning
about an uninitialized variable.

Strictly speaking, I think that you are right by saying "means nothing"
because the use of the uninitialized variable invokes undefined behavior
(and for this reason, I dislike this construct), but in practice it will
not make a difference.

-- Hannes

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

* Re: possible code error at run_command.c
  2009-12-21  7:18 ` Johannes Sixt
@ 2009-12-21  7:29   ` Frank Li
  2009-12-21  7:43     ` Johannes Sixt
  0 siblings, 1 reply; 11+ messages in thread
From: Frank Li @ 2009-12-21  7:29 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

> This is a commonly used idiom to avoid an (incorrect) compiler warning
> about an uninitialized variable.
>
> Strictly speaking, I think that you are right by saying "means nothing"
> because the use of the uninitialized variable invokes undefined behavior
> (and for this reason, I dislike this construct), but in practice it will
> not make a difference.
>

This error is captured at MSVC environment by run time varible check.
I prefer change it to
int failed_errno = errno;

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

* Re: possible code error at run_command.c
  2009-12-21  7:29   ` Frank Li
@ 2009-12-21  7:43     ` Johannes Sixt
  2009-12-21  8:18       ` Frank Li
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2009-12-21  7:43 UTC (permalink / raw)
  To: Frank Li; +Cc: git

Frank Li schrieb:
>> This is a commonly used idiom to avoid an (incorrect) compiler warning
>> about an uninitialized variable.
>>
>> Strictly speaking, I think that you are right by saying "means nothing"
>> because the use of the uninitialized variable invokes undefined behavior
>> (and for this reason, I dislike this construct), but in practice it will
>> not make a difference.
>>
> 
> This error is captured at MSVC environment by run time varible check.

Disable this check - it just takes away performance. :-)

(If you don't disable the check, then keep the required changes private.)

> I prefer change it to
> int failed_errno = errno;

You don't need to initialize the variable at all because it is always
initialized elsewhere before it is used. Perhaps MSVC is clever enough to
see it?

-- Hannes

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

* Re: possible code error at run_command.c
  2009-12-21  7:43     ` Johannes Sixt
@ 2009-12-21  8:18       ` Frank Li
  2009-12-21  8:30         ` Johannes Sixt
  0 siblings, 1 reply; 11+ messages in thread
From: Frank Li @ 2009-12-21  8:18 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git

>
> Disable this check - it just takes away performance. :-)

Release version will disable this.
Debug version enable this by default is just for find out code error.

>
> (If you don't disable the check, then keep the required changes private.)
>
>> I prefer change it to
>> int failed_errno = errno;
>
> You don't need to initialize the variable at all because it is always
> initialized elsewhere before it is used. Perhaps MSVC is clever enough to
> see it?
>

Maybe some excute path miss initialized it. Otherwise compiler will
not report warning.

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

* Re: possible code error at run_command.c
  2009-12-21  8:18       ` Frank Li
@ 2009-12-21  8:30         ` Johannes Sixt
  2009-12-21  8:41           ` Erik Faye-Lund
  0 siblings, 1 reply; 11+ messages in thread
From: Johannes Sixt @ 2009-12-21  8:30 UTC (permalink / raw)
  To: Frank Li; +Cc: git

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.

-- Hannes

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

* Re: possible code error at run_command.c
  2009-12-21  8:30         ` Johannes Sixt
@ 2009-12-21  8:41           ` Erik Faye-Lund
  2009-12-21  8:52             ` Johannes Sixt
  0 siblings, 1 reply; 11+ messages in thread
From: Erik Faye-Lund @ 2009-12-21  8:41 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Frank Li, git

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. 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.

Perhaps Frank has had to modify start_command for MSVC, and somehow
introduced such an error? I dunno.

-- 
Erik "kusma" Faye-Lund

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

* Re: possible code error at run_command.c
  2009-12-21  8:41           ` Erik Faye-Lund
@ 2009-12-21  8:52             ` Johannes Sixt
  2009-12-21  9:08               ` Erik Faye-Lund
  2009-12-21  9:13               ` Frank Li
  0 siblings, 2 replies; 11+ messages in thread
From: Johannes Sixt @ 2009-12-21  8:52 UTC (permalink / raw)
  To: kusmabite; +Cc: Frank Li, git

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

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

* Re: possible code error at run_command.c
  2009-12-21  8:52             ` Johannes Sixt
@ 2009-12-21  9:08               ` Erik Faye-Lund
  2009-12-21  9:13               ` Frank Li
  1 sibling, 0 replies; 11+ messages in thread
From: Erik Faye-Lund @ 2009-12-21  9:08 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Frank Li, git

On Mon, Dec 21, 2009 at 9:52 AM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> 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

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

* Re: possible code error at run_command.c
  2009-12-21  8:52             ` Johannes Sixt
  2009-12-21  9:08               ` Erik Faye-Lund
@ 2009-12-21  9:13               ` Frank Li
  1 sibling, 0 replies; 11+ messages in thread
From: Frank Li @ 2009-12-21  9:13 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: kusmabite, git

> This line will trigger the check. It initializes failed_errno with itself,
> which is still uninitialized at this time.
>
I see.
I always use release version at finial production.
This is not important. I read code again. There are not path.
Thank you take care.

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

end of thread, other threads:[~2009-12-21  9:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-21  6:46 possible code error at run_command.c Frank Li
2009-12-21  7:09 ` Wincent Colaiuta
2009-12-21  7:18 ` Johannes Sixt
2009-12-21  7:29   ` Frank Li
2009-12-21  7:43     ` Johannes Sixt
2009-12-21  8:18       ` Frank Li
2009-12-21  8:30         ` Johannes Sixt
2009-12-21  8:41           ` Erik Faye-Lund
2009-12-21  8:52             ` Johannes Sixt
2009-12-21  9:08               ` Erik Faye-Lund
2009-12-21  9:13               ` Frank Li

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).