{"thread":{"id":"32420","subject":"[PATCH] builtin/clean.c: Fix some sparse warnings","startedAt":"2012-12-20T18:33:55Z","lastAt":"2012-12-21T12:31:03Z","messageCount":2,"participants":["Ramsay Jones","Zoltan Klinger"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"205279","messageId":"50D35A13.9080605@ramsay1.demon.co.uk","threadId":"32420","inReplyTo":null,"subject":"[PATCH] builtin/clean.c: Fix some sparse warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsay1.demon.co.uk","sentAt":"2012-12-20T18:33:55Z","receivedAt":"2012-12-20T18:33:55Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSparse issues two \"Using plain integer as NULL pointer\" warnings\n(lines 41 and 47).\n\nThe first warning relates to the initializer expression in the\ndeclaration for the 'char *dir' variable. In order to suppress\nthe warning, we simply replace the zero initializer with NULL.\n\nThe second warning relates to an expression, as part of an if\nconditional, using the equality operator to compare the 'dir'\nvariable to zero. In order to suppress the warning, we replace\nthe 'dir == 0' expression with the more idiomatic '!dir'.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n---\n\nHi Zoltan,\n\nIf you have already updated your patch and made this redundant\n(it's been a few days since I read the list or fetched git.git),\nplease ignore this. Otherwise, could you please squash this into\nthe new version of commit 16e4033e6 (\"git-clean: Display more\naccurate delete messages\", 17-12-2012).\n\n[BTW, in the same conditional expression you have an strncmp()\ncall which doesn't quite follow the style/conventions of the\nexisting code.]\n\nThanks!\n\nATB,\nRamsay Jones\n\n builtin/clean.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 1c25a75..0c603c8 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -38,13 +38,13 @@ static void print_filtered(const char *msg, struct string_list *lst)\n {\n \tint i;\n \tchar *name;\n-\tchar *dir = 0;\n+\tchar *dir = NULL;\n \n \tsort_string_list(lst);\n \n \tfor (i = 0; i < lst->nr; i++) {\n \t\tname = lst->items[i].string;\n-\t\tif (dir == 0 || strncmp(name, dir, strlen(dir)) != 0)\n+\t\tif (!dir || strncmp(name, dir, strlen(dir)) != 0)\n \t\t\tprintf(\"%s %s\\n\", msg, name);\n \t\tif (name[strlen(name) - 1] == '/')\n \t\t\tdir = name;\n-- \n1.8.0\n"},{"id":"205329","messageId":"CAKJhZwSLSbR2pTB67-KLtrtuFsq6HtBGdHbN8h6tLiXBKynQzg@mail.gmail.com","threadId":"32420","inReplyTo":"50D35A13.9080605@ramsay1.demon.co.uk","subject":"Re: [PATCH] builtin/clean.c: Fix some sparse warnings","fromName":"Zoltan Klinger","fromEmail":"zoltan.klinger@gmail.com","sentAt":"2012-12-21T12:31:03Z","receivedAt":"2012-12-21T12:31:03Z","isPatch":true,"sender":{"key":"zoltan.klinger@gmail.com","avatar":"https://avatars.githubusercontent.com/u/95923?v=4"},"body":"Thanks, Ramsay. I am rewriting the whole patch to do things a better\nway (as kindly suggested by Junio). So the print_filtered() function\nis going to disappear, but thanks for pointing out the problems with\nthe existing code.\nCheers,\nZoltan\n\nOn 21 December 2012 05:33, Ramsay Jones <ramsay@ramsay1.demon.co.uk> wrote:\n>\n> Sparse issues two \"Using plain integer as NULL pointer\" warnings\n> (lines 41 and 47).\n>\n> The first warning relates to the initializer expression in the\n> declaration for the 'char *dir' variable. In order to suppress\n> the warning, we simply replace the zero initializer with NULL.\n>\n> The second warning relates to an expression, as part of an if\n> conditional, using the equality operator to compare the 'dir'\n> variable to zero. In order to suppress the warning, we replace\n> the 'dir == 0' expression with the more idiomatic '!dir'.\n>\n> Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>\n> ---\n>\n> Hi Zoltan,\n>\n> If you have already updated your patch and made this redundant\n> (it's been a few days since I read the list or fetched git.git),\n> please ignore this. Otherwise, could you please squash this into\n> the new version of commit 16e4033e6 (\"git-clean: Display more\n> accurate delete messages\", 17-12-2012).\n>\n> [BTW, in the same conditional expression you have an strncmp()\n> call which doesn't quite follow the style/conventions of the\n> existing code.]\n>\n> Thanks!\n>\n> ATB,\n> Ramsay Jones\n>\n>  builtin/clean.c | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/clean.c b/builtin/clean.c\n> index 1c25a75..0c603c8 100644\n> --- a/builtin/clean.c\n> +++ b/builtin/clean.c\n> @@ -38,13 +38,13 @@ static void print_filtered(const char *msg, struct string_list *lst)\n>  {\n>         int i;\n>         char *name;\n> -       char *dir = 0;\n> +       char *dir = NULL;\n>\n>         sort_string_list(lst);\n>\n>         for (i = 0; i < lst->nr; i++) {\n>                 name = lst->items[i].string;\n> -               if (dir == 0 || strncmp(name, dir, strlen(dir)) != 0)\n> +               if (!dir || strncmp(name, dir, strlen(dir)) != 0)\n>                         printf(\"%s %s\\n\", msg, name);\n>                 if (name[strlen(name) - 1] == '/')\n>                         dir = name;\n> --\n> 1.8.0\n>\n"}]}