{"thread":{"id":"29983","subject":"[PATCH] column.c: Fix an \"variable might be used uninitialized\" warning","startedAt":"2012-03-17T18:30:45Z","lastAt":"2012-03-17T18:30:45Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"187169","messageId":"4F64D855.4010302@ramsay1.demon.co.uk","threadId":"29983","inReplyTo":null,"subject":"[PATCH] column.c: Fix an \"variable might be used uninitialized\" warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2012-03-17T18:30:45Z","receivedAt":"2012-03-17T18:30:45Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nIn particular, gcc complains as follows:\n\n        CC column.o\n    column.c: In function 'print_columns':\n    column.c:305: warning: 'len' may be used uninitialized \\\n        in this function\n\nThe compiler can determine that the 'len' variable, which is\npassed by reference to the largest_block() function, may indeed\nnot be set. For example, if largest_block() returns zero, then\nthe 'len' output parameter will not be assigned to, which would\nresult in the local 'len' variable remaining uninitialised.\nThis would not lead to 'len' actually being used, however, since\nthe code checks for this case ('size' will be set to zero) and\nwill not execute the remainder of the loop body.\n\nIn order to suppress the warning, we simply initialise the 'len'\nvariable to zero.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nHi Nguyen,\n\nCould you please squash this into the relevant commit in your\nnd/column series. Thanks!\n\n[gcc v4.1.2 (on Linux) complains, but gcc v3.4.4 and gcc v4.4.0\ndo *not* complain.]\n\nATB,\nRamsay Jones\n\n column.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/column.c b/column.c\nindex 8214a9b..80183ea 100644\n--- a/column.c\n+++ b/column.c\n@@ -302,7 +302,7 @@ static struct area *find_large_blocks(const struct string_list *list, int *nr_p)\n \tmemset(&last, 0, sizeof(last));\n \n \tfor (i = 0; i < list->nr; i++) {\n-\t\tint len, size = largest_block(list, i, 0, &len);\n+\t\tint len = 0, size = largest_block(list, i, 0, &len);\n \t\tif (!size || len == 1)\n \t\t\tcontinue;\n \t\t/* the new found area is overlapped with the old one,\n-- \n1.7.9\n"}]}