diff options
author | Rory Bradford <roryrjb@gmail.com> | 2020-08-02 15:31:16 +0100 |
---|---|---|
committer | Rory Bradford <roryrjb@gmail.com> | 2020-08-02 15:31:16 +0100 |
commit | 11a95ee7fa9886ee2f62df940c7a53cfa1a8698a (patch) | |
tree | d5904cf69111a1d6eb2c2dd73257003e69079817 /rf.c | |
parent | 69631ff66e5afa6993037b60e2db4348a2f7b718 (diff) | |
download | rf-11a95ee7fa9886ee2f62df940c7a53cfa1a8698a.tar.gz |
Additional safety
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
Diffstat (limited to 'rf.c')
-rw-r--r-- | rf.c | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/rf.c b/rf.c index b183ecd..edaeef0 100644 --- a/rf.c +++ b/rf.c @@ -51,27 +51,33 @@ static int is_child(char *dirname) { } static int excluded(char *name) { - for (int i = 0; i < global_ignores->size; i++) { - int res = fnmatch(global_ignores->list[i], name, 0); + if (global_ignores != NULL) { + for (int i = 0; i < global_ignores->size; i++) { + int res = fnmatch(global_ignores->list[i], name, 0); - if (res == 0) { - return 1; + if (res == 0) { + return 1; + } } } - for (int i = 0; i < config_ignores->size; i++) { - int res = fnmatch(config_ignores->list[i], name, 0); + if (config_ignores != NULL) { + for (int i = 0; i < config_ignores->size; i++) { + int res = fnmatch(config_ignores->list[i], name, 0); - if (res == 0) { - return 1; + if (res == 0) { + return 1; + } } } - for (int i = 0; i < local_ignores->size; i++) { - int res = fnmatch(local_ignores->list[i], name, 0); + if (local_ignores != NULL) { + for (int i = 0; i < local_ignores->size; i++) { + int res = fnmatch(local_ignores->list[i], name, 0); - if (res == 0) { - return 1; + if (res == 0) { + return 1; + } } } @@ -122,15 +128,18 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname, for (; p < *pattern_count; p++) { char *pattern = patterns[p]; - if (switches->substring && - (strstr(switches->wholename ? full_path : entry->d_name, - pattern) != NULL)) { - matched = 1; - } else if (fnmatch(pattern, - switches->wholename ? full_path - : entry->d_name, - 0) == 0) { - matched = 1; + if (switches->substring) { + if (strstr( + switches->wholename ? full_path : entry->d_name, + pattern) != NULL) { + matched = 1; + } + } else { + if (fnmatch(pattern, + switches->wholename ? full_path : entry->d_name, + 0) == 0) { + matched = 1; + } } } |