From 0f6cb93a0910de6e142971b81d3717c26d94e860 Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Thu, 21 Aug 2014 20:51:02 +0200 Subject: Bug #165: Deletion of unnecessary null pointer checks The function "free" performs input parameter validation. http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html It is therefore not needed to check a passed pointer before this function call. A corresponding update suggestion was generated by the software "Coccinelle" from the following semantic patch approach. http://coccinelle.lip6.fr/ @Remove_unnecessary_pointer_checks1@ expression x; @@ -if (x != \(0 \| NULL\)) free(x); @Remove_unnecessary_pointer_checks2@ expression x; @@ -if (x != \(0 \| NULL\)) { free(x); x = \(0 \| NULL\); -} @Remove_unnecessary_pointer_checks3@ expression a, b; @@ -if (a != \(0 \| NULL\) && b != \(0 \| NULL\)) +if (a) free(b); @Remove_unnecessary_pointer_checks4@ expression a, b; @@ -if (a != \(0 \| NULL\) && b != \(0 \| NULL\)) { +if (a) { free(b); b = \(0 \| NULL\); } Signed-off-by: Markus Elfring --- main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 070d419..821f63b 100644 --- a/main.c +++ b/main.c @@ -810,8 +810,7 @@ int main(int argc, char **argv) filename[len-1] = '\0'; check_add_file(filename); } - if (filename != NULL) - free(filename); + free(filename); } for (i = 0; i < options->filecnt; i++) { -- cgit v1.2.3-70-g09d2