Fix compiler warnings in search.c

The calls to strstr() and strcasestr() in file_search() from search.c
result in compiler warnings when -Wnonnull is specified, because GCC's
"nonnull" attribute applies to these functions.

The logic from the file_search() call sites prevent NULL pointers from
being passed to these functions, but to protect against future
refactoring introducing this bug, check that the appropriate pointers
are non-NULL before calling the string functions.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
This commit is contained in:
Patrick McCarty
2017-09-28 13:18:11 -07:00
committed by Matthew Johnson
parent 7522e8d68b
commit 286435e9b0
+10 -6
View File
@@ -246,14 +246,18 @@ static bool file_search(char *filename, char *path, char *search_term)
return false;
}
pos = strstr(filename, path);
if (pos == NULL) {
return false;
if (path) {
pos = strstr(filename, path);
if (pos == NULL) {
return false;
}
}
/* match filename or substring of filename */
if (strcasestr(pos + strlen(path), search_term)) {
return true;
if (path && search_term) {
/* match filename or substring of filename */
if (strcasestr(pos + strlen(path), search_term)) {
return true;
}
}
return false;