summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorMarkus Elfring <elfring@users.sourceforge.net>2014-08-21 20:51:02 +0200
committerBert Münnich <ber.t@posteo.de>2014-08-22 19:24:08 +0200
commit0f6cb93a0910de6e142971b81d3717c26d94e860 (patch)
treee0cd28b350e05f97e8bdb88bd420dfced885ce8a /util.c
parent75a665670a60d6b7f0ee31dd8bcccbb0bc22d9bc (diff)
downloadnsxiv-0f6cb93a0910de6e142971b81d3717c26d94e860.tar.zst
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 <elfring@users.sourceforge.net>
Diffstat (limited to 'util.c')
-rw-r--r--util.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/util.c b/util.c
index c7b3bc8..3a5ae9a 100644
--- a/util.c
+++ b/util.c
@@ -198,18 +198,13 @@ char* absolute_path(const char *filename)
goto end;
error:
- if (path != NULL) {
- free(path);
- path = NULL;
- }
+ free(path);
+ path = NULL;
end:
- if (dirname != NULL)
- free(dirname);
- if (cwd != NULL)
- free(cwd);
- if (twd != NULL)
- free(twd);
+ free(dirname);
+ free(cwd);
+ free(twd);
return path;
}
@@ -254,7 +249,7 @@ int r_closedir(r_dir_t *rdir)
rdir->dir = NULL;
}
- if (rdir->d != 0 && rdir->name != NULL) {
+ if (rdir->d != 0) {
free(rdir->name);
rdir->name = NULL;
}