* Unreachable code in builtin-merge.c ?
@ 2009-10-23 15:03 Zivkov, Sasa
2009-10-23 15:12 ` Mikael Magnusson
2009-10-23 15:14 ` Joshua Roys
0 siblings, 2 replies; 4+ messages in thread
From: Zivkov, Sasa @ 2009-10-23 15:03 UTC (permalink / raw)
To: git@vger.kernel.org
In the try_merge_strategy function the expression in the following if statement seems to always evaluate to TRUE:
if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
If strategy is "recursive" then !strcmp(strategy, "subtree") evaluates to TRUE.
If strategy is "subtree" then !strcmp(strategy, "recursive") evaluates to TRUE.
If strategy is neither "recursive" nor "subtree" then any side of || evaluates to TRUE.
Looks like the code in the else block is unreachable?
Saša Živkov
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Unreachable code in builtin-merge.c ?
2009-10-23 15:03 Unreachable code in builtin-merge.c ? Zivkov, Sasa
@ 2009-10-23 15:12 ` Mikael Magnusson
2009-10-23 15:14 ` Joshua Roys
1 sibling, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2009-10-23 15:12 UTC (permalink / raw)
To: Zivkov, Sasa; +Cc: git@vger.kernel.org
2009/10/23 Zivkov, Sasa <sasa.zivkov@sap.com>:
> In the try_merge_strategy function the expression in the following if statement seems to always evaluate to TRUE:
>
> if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
>
> If strategy is "recursive" then !strcmp(strategy, "subtree") evaluates to TRUE.
> If strategy is "subtree" then !strcmp(strategy, "recursive") evaluates to TRUE.
> If strategy is neither "recursive" nor "subtree" then any side of || evaluates to TRUE.
>
> Looks like the code in the else block is unreachable?
You seem to have forgotten that strcmp returns 0 when the strings
match. (It returns -1 or 1 when they don't, depending on their
alphabetical ordering).
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Unreachable code in builtin-merge.c ?
2009-10-23 15:03 Unreachable code in builtin-merge.c ? Zivkov, Sasa
2009-10-23 15:12 ` Mikael Magnusson
@ 2009-10-23 15:14 ` Joshua Roys
2009-10-23 15:39 ` Zivkov, Sasa
1 sibling, 1 reply; 4+ messages in thread
From: Joshua Roys @ 2009-10-23 15:14 UTC (permalink / raw)
To: Zivkov, Sasa; +Cc: git@vger.kernel.org
On 10/23/2009 11:03 AM, Zivkov, Sasa wrote:
> In the try_merge_strategy function the expression in the following if statement seems to always evaluate to TRUE:
>
> if (!strcmp(strategy, "recursive") || !strcmp(strategy, "subtree")) {
>
> If strategy is "recursive" then !strcmp(strategy, "subtree") evaluates to TRUE.
> If strategy is "subtree" then !strcmp(strategy, "recursive") evaluates to TRUE.
> If strategy is neither "recursive" nor "subtree" then any side of || evaluates to TRUE.
>
> Looks like the code in the else block is unreachable?
>
>
> Saša Živkov
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
Hello,
Not quite :) The strcmp() function actually returns 0 when the strings
match (I know, it looks weird "!strcmp" -> "not string compare?!"), so
the "if" really means: "if strategy is equal to 'recursive' or
'subtree', do the following..."
Hope to help,
Josh
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Unreachable code in builtin-merge.c ?
2009-10-23 15:14 ` Joshua Roys
@ 2009-10-23 15:39 ` Zivkov, Sasa
0 siblings, 0 replies; 4+ messages in thread
From: Zivkov, Sasa @ 2009-10-23 15:39 UTC (permalink / raw)
To: git@vger.kernel.org
> Not quite :) The strcmp() function actually returns 0 when the strings
> match (I know, it looks weird "!strcmp" -> "not string compare?!"), so
Right! Now I remember it :-)
This is what happens when one looks at C code after some 10+ years of !C development ;-)
Saša Živkov
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-10-23 15:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-23 15:03 Unreachable code in builtin-merge.c ? Zivkov, Sasa
2009-10-23 15:12 ` Mikael Magnusson
2009-10-23 15:14 ` Joshua Roys
2009-10-23 15:39 ` Zivkov, Sasa
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.