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

Re: Unreachable code in builtin-merge.c ?

From
JRJoshua Roys <roysjosh@gmail.com>
Date
Oct 23, 2009, 15:14 UTC
Message-ID
<4AE1C863.3070907@gmail.com>
In-Reply-To
<B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp>
On 10/23/2009 11:03 AM, Zivkov, Sasa wrote:
Show 16 quoted lines
> 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
Previous: Mikael MagnussonNext: Zivkov, Sasa
Message 3 of 4 in “Unreachable code in builtin-merge.c ?”
  1. Zivkov, SasaOct 23, 2009
  2. Mikael MagnussonOct 23, 2009
  3. Joshua RoysOct 23, 2009
  4. Zivkov, SasaOct 23, 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.