# Unreachable code in builtin-merge.c ?

4 messages from 2009-10-23 to 2009-10-23. Participants: Zivkov, Sasa, Mikael Magnusson, Joshua Roys.
Thread: https://gitlist.dev/t/21337

## Zivkov, Sasa, 2009-10-23 15:03

Subject: Unreachable code in builtin-merge.c ?
Message-ID: <B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp>
URL: https://gitlist.dev/e/B221C4384AE5104EB414A877DFD0372C0B0092C0C5%40DEWDFECCR04.wdf.sap.corp

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

```

## Mikael Magnusson, 2009-10-23 15:12

Subject: Re: Unreachable code in builtin-merge.c ?
Message-ID: <237967ef0910230812r621ac705qb029dade20c455a7@mail.gmail.com>
URL: https://gitlist.dev/e/237967ef0910230812r621ac705qb029dade20c455a7%40mail.gmail.com
In-Reply-To: <B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp>

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

```

## Joshua Roys, 2009-10-23 15:14

Subject: Re: Unreachable code in builtin-merge.c ?
Message-ID: <4AE1C863.3070907@gmail.com>
URL: https://gitlist.dev/e/4AE1C863.3070907%40gmail.com
In-Reply-To: <B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp>

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

```

## Zivkov, Sasa, 2009-10-23 15:39

Subject: RE: Unreachable code in builtin-merge.c ?
Message-ID: <B221C4384AE5104EB414A877DFD0372C0B0092C117@DEWDFECCR04.wdf.sap.corp>
URL: https://gitlist.dev/e/B221C4384AE5104EB414A877DFD0372C0B0092C117%40DEWDFECCR04.wdf.sap.corp
In-Reply-To: <4AE1C863.3070907@gmail.com>

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

```
