builtin/clean.c: Fix some sparse warnings
PATCH 1/1 builtin/clean.c: Fix some sparse warnings
Sparse issues two "Using plain integer as NULL pointer" warnings (lines 41 and 47).
The first warning relates to the initializer expression in the declaration for the 'char *dir' variable. In order to suppress the warning, we simply replace the zero initializer with NULL.
The second warning relates to an expression, as part of an if conditional, using the equality operator to compare the 'dir' variable to zero. In order to suppress the warning, we replace the 'dir == 0' expression with the more idiomatic '!dir'.
---
Hi Zoltan,
If you have already updated your patch and made this redundant (it's been a few days since I read the list or fetched git.git), please ignore this. Otherwise, could you please squash this into the new version of commit 16e4033e6 ("git-clean: Display more accurate delete messages", 17-12-2012).
[BTW, in the same conditional expression you have an strncmp() call which doesn't quite follow the style/conventions of the existing code.]
Thanks!
ATB,
Ramsay Jones
builtin/clean.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/clean.c +2 -2
@@ -38,13 +38,13 @@ static void print_filtered(const char *msg, struct string_list *lst) {int i;char *name; -char *dir =0 ; +char *dir =NULL ;sort_string_list (lst);for (i =0 ; i < lst->nr; i++) { name = lst->items[i].string; -if (dir ==0 ||strncmp (name, dir,strlen (dir)) !=0 ) +if (!dir ||strncmp (name, dir,strlen (dir)) !=0 )printf ("%s %s\n" , msg, name);if (name[strlen (name) -1 ] =='/' ) dir = name;
Signature · 1 line
1.8.0
Thanks, Ramsay. I am rewriting the whole patch to do things a better way (as kindly suggested by Junio). So the print_filtered() function is going to disappear, but thanks for pointing out the problems with the existing code.
Cheers,
Zoltan
Quoted 59 lines · Ramsay Jones
Sparse issues two "Using plain integer as NULL pointer" warnings (lines 41 and 47).
The first warning relates to the initializer expression in the declaration for the 'char *dir' variable. In order to suppress the warning, we simply replace the zero initializer with NULL.
The second warning relates to an expression, as part of an if conditional, using the equality operator to compare the 'dir' variable to zero. In order to suppress the warning, we replace the 'dir == 0' expression with the more idiomatic '!dir'.
Signed-off-by Ramsay Jones <[email protected]>---
Hi Zoltan,
If you have already updated your patch and made this redundant (it's been a few days since I read the list or fetched git.git), please ignore this. Otherwise, could you please squash this into the new version of commit
16e4033e6("git-clean: Display more accurate delete messages", 17-12-2012).[BTW, in the same conditional expression you have an
strncmp()call which doesn't quite follow the style/conventions of the existing code.]Thanks!
ATB,
Ramsay Jonesbuiltin/clean.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)builtin/clean.c +2
-3@@ -38,13 +38,13 @@ static void print_filtered(const char *msg, struct string_list *lst) {int i;char *name; -char *dir =0 ; +char *dir =NULL ;sort_string_list (lst);for (i =0 ; i < lst->nr; i++) { name = lst->items[i].string; -if (dir ==0 ||strncmp (name, dir,strlen (dir)) !=0 ) +if (!dir ||strncmp (name, dir,strlen (dir)) !=0 )printf ("%s %s\n" , msg, name);if (name[strlen (name) -1 ] =='/' ) dir = name; --1.8.0