]> granicus.if.org Git - file/commitdiff
Portability fix, don't call qsort with NULL/0. Found by coverity
authorChristos Zoulas <christos@zoulas.com>
Wed, 1 Aug 2018 10:18:02 +0000 (10:18 +0000)
committerChristos Zoulas <christos@zoulas.com>
Wed, 1 Aug 2018 10:18:02 +0000 (10:18 +0000)
src/apprentice.c

index 4d411e66ab835646fe28e3086fb5e51d4219bcfb..45cf2a9fb8e0031be3eaf614c96ead55ea7b7a85 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef        lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.275 2018/08/01 10:14:10 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.276 2018/08/01 10:18:02 christos Exp $")
 #endif /* lint */
 
 #include "magic.h"
@@ -1391,12 +1391,14 @@ apprentice_load(struct magic_set *ms, const char *fn, int action)
                        filearr[files++] = mfn;
                }
                closedir(dir);
-               qsort(filearr, files, sizeof(*filearr), cmpstrp);
-               for (i = 0; i < files; i++) {
-                       load_1(ms, action, filearr[i], &errs, mset);
-                       free(filearr[i]);
+               if (filearr) {
+                       qsort(filearr, files, sizeof(*filearr), cmpstrp);
+                       for (i = 0; i < files; i++) {
+                               load_1(ms, action, filearr[i], &errs, mset);
+                               free(filearr[i]);
+                       }
+                       free(filearr);
                }
-               free(filearr);
        } else
                load_1(ms, action, fn, &errs, mset);
        if (errs)