{"thread":{"id":"36421","subject":"[PATCH] config.c: fix a compiler warning","startedAt":"2014-04-16T14:13:53Z","lastAt":"2014-04-16T17:21:58Z","messageCount":5,"participants":["Stepan Kasal","Jeff King","Torsten Bögershausen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"238933","messageId":"20140416141353.GA9676@camelia.ucw.cz","threadId":"36421","inReplyTo":null,"subject":"[PATCH] config.c: fix a compiler warning","fromName":"Stepan Kasal","fromEmail":"kasal@ucw.cz","sentAt":"2014-04-16T14:13:53Z","receivedAt":"2014-04-16T14:13:53Z","isPatch":true,"sender":{"key":"kasal@ucw.cz","avatar":"https://avatars.githubusercontent.com/u/1481596?v=4"},"body":"Date: Thu, 10 Apr 2014 16:37:15 +0200\n\nThis change fixes a gcc warning when building msysGit.\n---\n config.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 314d8ee..0b7e4f8 100644\n--- a/config.c\n+++ b/config.c\n@@ -572,7 +572,7 @@ static void die_bad_number(const char *name, const char *value)\n \n int git_config_int(const char *name, const char *value)\n {\n-\tint ret;\n+\tint ret = 0;\n \tif (!git_parse_int(value, &ret))\n \t\tdie_bad_number(name, value);\n \treturn ret;\n@@ -580,7 +580,7 @@ int git_config_int(const char *name, const char *value)\n \n int64_t git_config_int64(const char *name, const char *value)\n {\n-\tint64_t ret;\n+\tint64_t ret = 0;\n \tif (!git_parse_int64(value, &ret))\n \t\tdie_bad_number(name, value);\n \treturn ret;\n-- \n1.9.2.msysgit.0.154.g978f18d\n"},{"id":"238937","messageId":"20140416152920.GA4691@sigill.intra.peff.net","threadId":"36421","inReplyTo":"20140416141353.GA9676@camelia.ucw.cz","subject":"Re: [PATCH] config.c: fix a compiler warning","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-04-16T15:29:20Z","receivedAt":"2014-04-16T15:29:20Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Apr 16, 2014 at 04:13:53PM +0200, Stepan Kasal wrote:\n\n> Date: Thu, 10 Apr 2014 16:37:15 +0200\n> \n> This change fixes a gcc warning when building msysGit.\n\nWhat warning? I'm assuming -Wuninitialized?\n\n> diff --git a/config.c b/config.c\n> index 314d8ee..0b7e4f8 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -572,7 +572,7 @@ static void die_bad_number(const char *name, const char *value)\n>  \n>  int git_config_int(const char *name, const char *value)\n>  {\n> -\tint ret;\n> +\tint ret = 0;\n>  \tif (!git_parse_int(value, &ret))\n>  \t\tdie_bad_number(name, value);\n>  \treturn ret;\n\nHmph. Generally gcc should assume that a variable is initialized after a\npointer to it is passed into a function. Unless it inlines that function\nand can see that it isn't. But if we do inline git_parse_int, we see\nthat it \"ret\" is always initialized if it returns non-zero.\n\nIf it also inlines die_bad_number, it would see that we end in die(),\nwhich is marked NORETURN. But if it does not, it will not realize that\nwe do not get to \"return ret\" in that case.\n\nSo perhaps a better solution is:\n\ndiff --git a/config.c b/config.c\nindex 6821cef..a30cb5c 100644\n--- a/config.c\n+++ b/config.c\n@@ -557,6 +557,7 @@ int git_parse_ulong(const char *value, unsigned long *ret)\n \treturn 1;\n }\n \n+NORETURN\n static void die_bad_number(const char *name, const char *value)\n {\n \tconst char *reason = errno == ERANGE ?\n\nDoes that also silence the warning?\n\n-Peff\n"},{"id":"238940","messageId":"534EB1FB.5040405@web.de","threadId":"36421","inReplyTo":"20140416152920.GA4691@sigill.intra.peff.net","subject":"Re: [PATCH] config.c: fix a compiler warning","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2014-04-16T16:38:19Z","receivedAt":"2014-04-16T16:38:19Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2014-04-16 17.29, Jeff King wrote:\n> On Wed, Apr 16, 2014 at 04:13:53PM +0200, Stepan Kasal wrote:\n> \n>> Date: Thu, 10 Apr 2014 16:37:15 +0200\n>>\n>> This change fixes a gcc warning when building msysGit.\n\n[]\n> +NORETURN\n>  static void die_bad_number(const char *name, const char *value)\n>  {\n>  \tconst char *reason = errno == ERANGE ?\n> \n> Does that also silence the warning?\n> \n> -Peff\nThis works under gcc 4.2.1 Mac OS: the warning is away.\n"},{"id":"238944","messageId":"20140416165146.GA16695@sigill.intra.peff.net","threadId":"36421","inReplyTo":"534EB1FB.5040405@web.de","subject":"[PATCH] config.c: mark die_bad_number as NORETURN","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-04-16T16:51:47Z","receivedAt":"2014-04-16T16:51:47Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Apr 16, 2014 at 06:38:19PM +0200, Torsten Bögershausen wrote:\n\n> > Does that also silence the warning?\n> > \n> This works under gcc 4.2.1 Mac OS: the warning is away.\n\nThanks. I couldn't test myself, as I could not get gcc to generate the\nwarning in the first place, but I do not have anything as old as 4.2 on\nhand.\n\nHere it is with a commit message.\n\n-- >8 --\nSubject: config.c: mark die_bad_number as NORETURN\n\nThis can help avoid -Wuninitialized false positives in\ngit_config_int and git_config_ulong, as the compiler now\nknows that we do not return \"ret\" if we hit the error\ncodepath.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n config.c | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/config.c b/config.c\nindex 6821cef..a30cb5c 100644\n--- a/config.c\n+++ b/config.c\n@@ -557,6 +557,7 @@ int git_parse_ulong(const char *value, unsigned long *ret)\n \treturn 1;\n }\n \n+NORETURN\n static void die_bad_number(const char *name, const char *value)\n {\n \tconst char *reason = errno == ERANGE ?\n-- \n1.9.1.656.ge8a0637\n"},{"id":"238952","messageId":"xmqq7g6pi409.fsf@gitster.dls.corp.google.com","threadId":"36421","inReplyTo":"20140416165146.GA16695@sigill.intra.peff.net","subject":"Re: [PATCH] config.c: mark die_bad_number as NORETURN","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-04-16T17:21:58Z","receivedAt":"2014-04-16T17:21:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Apr 16, 2014 at 06:38:19PM +0200, Torsten Bögershausen wrote:\n>\n>> > Does that also silence the warning?\n>> > \n>> This works under gcc 4.2.1 Mac OS: the warning is away.\n>\n> Thanks. I couldn't test myself, as I could not get gcc to generate the\n> warning in the first place, but I do not have anything as old as 4.2 on\n> hand.\n>\n> Here it is with a commit message.\n>\n> -- >8 --\n> Subject: config.c: mark die_bad_number as NORETURN\n>\n> This can help avoid -Wuninitialized false positives in\n> git_config_int and git_config_ulong, as the compiler now\n> knows that we do not return \"ret\" if we hit the error\n> codepath.\n\nThanks for clearly solving the issue and describing the solution.\nWill queue.\n\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n>  config.c | 1 +\n>  1 file changed, 1 insertion(+)\n>\n> diff --git a/config.c b/config.c\n> index 6821cef..a30cb5c 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -557,6 +557,7 @@ int git_parse_ulong(const char *value, unsigned long *ret)\n>  \treturn 1;\n>  }\n>  \n> +NORETURN\n>  static void die_bad_number(const char *name, const char *value)\n>  {\n>  \tconst char *reason = errno == ERANGE ?\n"}]}