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>
This commit is contained in:
parent
75a665670a
commit
0f6cb93a09
1
main.c
1
main.c
|
@ -810,7 +810,6 @@ int main(int argc, char **argv)
|
|||
filename[len-1] = '\0';
|
||||
check_add_file(filename);
|
||||
}
|
||||
if (filename != NULL)
|
||||
free(filename);
|
||||
}
|
||||
|
||||
|
|
3
thumbs.c
3
thumbs.c
|
@ -176,7 +176,6 @@ void tns_init(tns_t *tns, const fileinfo_t *files, int cnt, int *sel, win_t *win
|
|||
dsuffix = "/.cache";
|
||||
}
|
||||
if (homedir != NULL) {
|
||||
if (cache_dir != NULL)
|
||||
free(cache_dir);
|
||||
len = strlen(homedir) + strlen(dsuffix) + 6;
|
||||
cache_dir = (char*) s_malloc(len);
|
||||
|
@ -204,11 +203,9 @@ void tns_free(tns_t *tns)
|
|||
tns->thumbs = NULL;
|
||||
}
|
||||
|
||||
if (cache_dir != NULL) {
|
||||
free(cache_dir);
|
||||
cache_dir = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool tns_load(tns_t *tns, int n, bool force)
|
||||
{
|
||||
|
|
7
util.c
7
util.c
|
@ -198,17 +198,12 @@ char* absolute_path(const char *filename)
|
|||
goto end;
|
||||
|
||||
error:
|
||||
if (path != NULL) {
|
||||
free(path);
|
||||
path = NULL;
|
||||
}
|
||||
|
||||
end:
|
||||
if (dirname != NULL)
|
||||
free(dirname);
|
||||
if (cwd != NULL)
|
||||
free(cwd);
|
||||
if (twd != NULL)
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue