{"thread":{"id":"38146","subject":"[PATCH] Avoid gcc compiler warning","startedAt":"2014-12-08T16:38:59Z","lastAt":"2014-12-09T09:48:36Z","messageCount":3,"participants":["Johannes Schindelin","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"253369","messageId":"b9e1cb1f858e71b964be4f752fcebc22cd944ebc.1418056722.git.johannes.schindelin@gmx.de","threadId":"38146","inReplyTo":"cover.1418056722.git.johannes.schindelin@gmx.de","subject":"[PATCH] Avoid gcc compiler warning","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-08T16:38:59Z","receivedAt":"2014-12-08T16:38:59Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"At least on this developer's MacOSX (Snow Leopard, gcc-4.2.1), GCC prints\na warning that 'hash' may be used uninitialized when compiling\ntest-hashmap that 'hash' may be used uninitialized (but GCC 4.6.3 on this\ndeveloper's Ubuntu server does not report this problem).\n\nSince hash() is called from perf_hashmap() which accepts an unchecked\ninteger value from the command line, the warning appears to be legitimate,\neven if the test-hashmap command is only called from the test suite.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n test-hashmap.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/test-hashmap.c b/test-hashmap.c\nindex 07aa7ec..40a126d 100644\n--- a/test-hashmap.c\n+++ b/test-hashmap.c\n@@ -62,6 +62,8 @@ static unsigned int hash(unsigned int method, unsigned int i, const char *key)\n \tcase HASH_METHOD_0:\n \t\thash = 0;\n \t\tbreak;\n+\tdefault:\n+\t\tdie(\"Unknown method: %d\", method);\n \t}\n \n \tif (method & HASH_METHOD_X2)\n-- \n2.0.0.rc3.9669.g840d1f9\n"},{"id":"253406","messageId":"20141209084728.GA13123@peff.net","threadId":"38146","inReplyTo":"b9e1cb1f858e71b964be4f752fcebc22cd944ebc.1418056722.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] Avoid gcc compiler warning","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-12-09T08:47:28Z","receivedAt":"2014-12-09T08:47:28Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 08, 2014 at 05:38:59PM +0100, Johannes Schindelin wrote:\n\n> At least on this developer's MacOSX (Snow Leopard, gcc-4.2.1), GCC prints\n> a warning that 'hash' may be used uninitialized when compiling\n> test-hashmap that 'hash' may be used uninitialized (but GCC 4.6.3 on this\n> developer's Ubuntu server does not report this problem).\n> \n> Since hash() is called from perf_hashmap() which accepts an unchecked\n> integer value from the command line, the warning appears to be legitimate,\n> even if the test-hashmap command is only called from the test suite.\n\nI think the older gcc is wrong; we are switching on \"method & 3\", which\nmust be in the range 0-3 (and we cover all cases).\n\nI do not mind silencing the warning anyway, but see this discussion:\n\n  http://thread.gmane.org/gmane.comp.version-control.git/258186\n\nThe thread seems very broken in gmane, but it continues here:\n\n  http://article.gmane.org/gmane.comp.version-control.git/258232\n\n  http://thread.gmane.org/gmane.comp.version-control.git/258245\n\n  http://article.gmane.org/gmane.comp.version-control.git/258264\n\n-Peff\n"},{"id":"253407","messageId":"alpine.DEB.1.00.1412091039130.13845@s15462909.onlinehome-server.info","threadId":"38146","inReplyTo":"20141209084728.GA13123@peff.net","subject":"Re: [PATCH] Avoid gcc compiler warning","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2014-12-09T09:48:36Z","receivedAt":"2014-12-09T09:48:36Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Peff,\n\nOn Tue, 9 Dec 2014, Jeff King wrote:\n\n> On Mon, Dec 08, 2014 at 05:38:59PM +0100, Johannes Schindelin wrote:\n> \n> > At least on this developer's MacOSX (Snow Leopard, gcc-4.2.1), GCC prints\n> > a warning that 'hash' may be used uninitialized when compiling\n> > test-hashmap that 'hash' may be used uninitialized (but GCC 4.6.3 on this\n> > developer's Ubuntu server does not report this problem).\n> > \n> > Since hash() is called from perf_hashmap() which accepts an unchecked\n> > integer value from the command line, the warning appears to be legitimate,\n> > even if the test-hashmap command is only called from the test suite.\n> \n> I think the older gcc is wrong;\n\nThanks for pointing to the older thread. It just happened to make it\ninconvenient to develop the rather huge fsck api topic branch I submitted\nyesterday because my vi kept jumping to test-hashmap.c because of that\ncompiler warning (and as you know, not everybody has the luxury of being\nable to upgrade their gcc *cough* *Xcode* *cough* *Snow Leopard*).\n\n> we are switching on \"method & 3\", which must be in the range 0-3 (and we\n> cover all cases).\n\nThat is of course correct, but still does not address the compiler\nwarning.\n\nJunio, you said that you would prefer the useless initialization, so here\ngoes:\n\n-- snipsnap --\nSubject: [PATCH] Avoid gcc compiler warning\n\nAt least on this developer's MacOSX (Snow Leopard, gcc-4.2.1), GCC prints\na warning that 'hash' may be used uninitialized when compiling\ntest-hashmap that 'hash' may be used uninitialized (but GCC 4.6.3 on this\ndeveloper's Ubuntu server does not report this problem).\n\nThe old compiler is wrong, of course, as the switch(method & 3) statement\nalready handles all the possible cases, but that does not help in a\nscenario where it is hard or impossible to upgrade to a newer compiler\n(e.g. being stuck on an older MacOSX and having to rely on Xcode).\n\nSo let's just initialize the variable and be done with it, it is hardly a\ncrucial part of the code because it is only used by the test suite and\ninvisible to the end users.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n test-hashmap.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/test-hashmap.c b/test-hashmap.c\nindex 07aa7ec..cc2891d 100644\n--- a/test-hashmap.c\n+++ b/test-hashmap.c\n@@ -47,7 +47,7 @@ static struct test_entry *alloc_test_entry(int hash,\nchar *key, int klen,\n \n static unsigned int hash(unsigned int method, unsigned int i, const char\n*key)\n {\n-\tunsigned int hash;\n+\tunsigned int hash = 0;\n \tswitch (method & 3)\n \t{\n \tcase HASH_METHOD_FNV:\n-- \n2.0.0.rc3.9669.g840d1f9\n"}]}