{"thread":{"id":"21337","subject":"Unreachable code in builtin-merge.c ?","startedAt":"2009-10-23T15:03:53Z","lastAt":"2009-10-23T15:39:03Z","messageCount":4,"participants":["Zivkov, Sasa","Mikael Magnusson","Joshua Roys"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"125787","messageId":"B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp","threadId":"21337","inReplyTo":null,"subject":"Unreachable code in builtin-merge.c ?","fromName":"Zivkov, Sasa","fromEmail":"sasa.zivkov@sap.com","sentAt":"2009-10-23T15:03:53Z","receivedAt":"2009-10-23T15:03:53Z","isPatch":false,"sender":{"key":"sasa.zivkov@sap.com","avatar":null},"body":"In the try_merge_strategy function the expression in the following if statement seems to always evaluate to TRUE:\n\n        if (!strcmp(strategy, \"recursive\") || !strcmp(strategy, \"subtree\")) {\n\nIf strategy is \"recursive\" then !strcmp(strategy, \"subtree\") evaluates to TRUE.\nIf strategy is \"subtree\" then !strcmp(strategy, \"recursive\") evaluates to TRUE.\nIf strategy is neither \"recursive\" nor \"subtree\" then any side of || evaluates to TRUE.\n\nLooks like the code in the else block is unreachable?\n\n\nSaša Živkov\n"},{"id":"125788","messageId":"237967ef0910230812r621ac705qb029dade20c455a7@mail.gmail.com","threadId":"21337","inReplyTo":"B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp","subject":"Re: Unreachable code in builtin-merge.c ?","fromName":"Mikael Magnusson","fromEmail":"mikachu@gmail.com","sentAt":"2009-10-23T15:12:43Z","receivedAt":"2009-10-23T15:12:43Z","isPatch":false,"sender":{"key":"mikachu@gmail.com","avatar":null},"body":"2009/10/23 Zivkov, Sasa <sasa.zivkov@sap.com>:\n> In the try_merge_strategy function the expression in the following if statement seems to always evaluate to TRUE:\n>\n>        if (!strcmp(strategy, \"recursive\") || !strcmp(strategy, \"subtree\")) {\n>\n> If strategy is \"recursive\" then !strcmp(strategy, \"subtree\") evaluates to TRUE.\n> If strategy is \"subtree\" then !strcmp(strategy, \"recursive\") evaluates to TRUE.\n> If strategy is neither \"recursive\" nor \"subtree\" then any side of || evaluates to TRUE.\n>\n> Looks like the code in the else block is unreachable?\n\nYou seem to have forgotten that strcmp returns 0 when the strings\nmatch. (It returns -1 or 1 when they don't, depending on their\nalphabetical ordering).\n\n-- \nMikael Magnusson\n"},{"id":"125789","messageId":"4AE1C863.3070907@gmail.com","threadId":"21337","inReplyTo":"B221C4384AE5104EB414A877DFD0372C0B0092C0C5@DEWDFECCR04.wdf.sap.corp","subject":"Re: Unreachable code in builtin-merge.c ?","fromName":"Joshua Roys","fromEmail":"roysjosh@gmail.com","sentAt":"2009-10-23T15:14:43Z","receivedAt":"2009-10-23T15:14:43Z","isPatch":false,"sender":{"key":"roysjosh@gmail.com","avatar":null},"body":"On 10/23/2009 11:03 AM, Zivkov, Sasa wrote:\n> In the try_merge_strategy function the expression in the following if statement seems to always evaluate to TRUE:\n>\n>          if (!strcmp(strategy, \"recursive\") || !strcmp(strategy, \"subtree\")) {\n>\n> If strategy is \"recursive\" then !strcmp(strategy, \"subtree\") evaluates to TRUE.\n> If strategy is \"subtree\" then !strcmp(strategy, \"recursive\") evaluates to TRUE.\n> If strategy is neither \"recursive\" nor \"subtree\" then any side of || evaluates to TRUE.\n>\n> Looks like the code in the else block is unreachable?\n>\n>\n> Saša Živkov\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n\nHello,\n\nNot quite :)  The strcmp() function actually returns 0 when the strings \nmatch (I know, it looks weird \"!strcmp\" -> \"not string compare?!\"), so \nthe \"if\" really means: \"if strategy is equal to 'recursive' or \n'subtree', do the following...\"\n\nHope to help,\n\nJosh\n"},{"id":"125790","messageId":"B221C4384AE5104EB414A877DFD0372C0B0092C117@DEWDFECCR04.wdf.sap.corp","threadId":"21337","inReplyTo":"4AE1C863.3070907@gmail.com","subject":"RE: Unreachable code in builtin-merge.c ?","fromName":"Zivkov, Sasa","fromEmail":"sasa.zivkov@sap.com","sentAt":"2009-10-23T15:39:03Z","receivedAt":"2009-10-23T15:39:03Z","isPatch":false,"sender":{"key":"sasa.zivkov@sap.com","avatar":null},"body":"> Not quite :)  The strcmp() function actually returns 0 when the strings\n> match (I know, it looks weird \"!strcmp\" -> \"not string compare?!\"), so\n\nRight! Now I remember it :-)\n\nThis is what happens when one looks at C code after some 10+ years of !C development ;-)\n\nSaša Živkov\n"}]}