]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util: clang: Fix a dereference of a null pointer warning(s)
authorNoel Power <noel.power@suse.com>
Fri, 24 May 2019 14:03:37 +0000 (14:03 +0000)
committerNoel Power <npower@samba.org>
Tue, 11 Jun 2019 12:10:17 +0000 (12:10 +0000)
Fixes:

lib/util/ms_fnmatch.c:75:8: warning: Access to field 'predot' results in a dereference of a null pointer (loaded from variable 'max_n') <--[clang]
                        if (max_n->predot && max_n->predot <= n) {
                            ^
lib/util/ms_fnmatch.c:91:8: warning: Access to field 'predot' results in a dereference of a null pointer (loaded from variable 'max_n') <--[clang]
                        if (max_n->predot && max_n->predot <= n) {

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer gary@catalyst.net.nz
lib/util/ms_fnmatch.c

index 636ac399f66e421c69f5ec8a71337709dd7656fb..5e05312f25afd6299e3441b6ce68d45f6fe9f71e 100644 (file)
@@ -72,7 +72,8 @@ static int ms_fnmatch_core(const char *p, const char *n,
                switch (c) {
                case '*':
                        /* a '*' matches zero or more characters of any type */
-                       if (max_n->predot && max_n->predot <= n) {
+                       if (max_n != NULL && max_n->predot &&
+                           max_n->predot <= n) {
                                return null_match(p);
                        }
                        for (i=0; n[i]; i += size_n) {
@@ -81,17 +82,22 @@ static int ms_fnmatch_core(const char *p, const char *n,
                                        return 0;
                                }
                        }
-                       if (!max_n->predot || max_n->predot > n) max_n->predot = n;
+                       if (max_n != NULL && (!max_n->predot ||
+                           max_n->predot > n)) {
+                               max_n->predot = n;
+                       }
                        return null_match(p);
 
                case '<':
                        /* a '<' matches zero or more characters of
                           any type, but stops matching at the last
                           '.' in the string. */
-                       if (max_n->predot && max_n->predot <= n) {
+                       if (max_n != NULL && max_n->predot &&
+                           max_n->predot <= n) {
                                return null_match(p);
                        }
-                       if (max_n->postdot && max_n->postdot <= n && n <= ldot) {
+                       if (max_n != NULL && max_n->postdot &&
+                           max_n->postdot <= n && n <= ldot) {
                                return -1;
                        }
                        for (i=0; n[i]; i += size_n) {
@@ -99,11 +105,19 @@ static int ms_fnmatch_core(const char *p, const char *n,
                                if (ms_fnmatch_core(p, n+i, max_n+1, ldot, is_case_sensitive) == 0) return 0;
                                if (n+i == ldot) {
                                        if (ms_fnmatch_core(p, n+i+size_n, max_n+1, ldot, is_case_sensitive) == 0) return 0;
-                                       if (!max_n->postdot || max_n->postdot > n) max_n->postdot = n;
+                                       if (max_n != NULL) {
+                                               if (!max_n->postdot ||
+                                                   max_n->postdot > n) {
+                                                       max_n->postdot = n;
+                                               }
+                                       }
                                        return -1;
                                }
                        }
-                       if (!max_n->predot || max_n->predot > n) max_n->predot = n;
+                       if (max_n != NULL && (!max_n->predot ||
+                           max_n->predot > n)) {
+                               max_n->predot = n;
+                       }
                        return null_match(p);
 
                case '?':