]> granicus.if.org Git - sudo/commitdiff
Stop testing unspecified behavior in fnmatch
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 6 Apr 2011 19:13:23 +0000 (15:13 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 6 Apr 2011 19:13:23 +0000 (15:13 -0400)
Make glob test more portable

compat/regress/fnmatch/fnm_test.in
compat/regress/glob/globtest.c

index e19ec7df23d71be5f40420a3f2892ae12451aad3..5d452efe20ea8ede3203a3f7169bc648e4a2aa16 100644 (file)
@@ -1,5 +1,5 @@
 /bin/[[:alpha:][:alnum:]]* /bin/ls FNM_PATHNAME 0
-/bin/[[:upper:]][[:alnum:]] /bin/ls FNM_CASEFOLD 0
+/bin/[[:alpha:][:alnum:]]* /bin/LS FNM_CASEFOLD 0
 /bin/[[:opper:][:alnum:]]* /bin/ls NONE 1
 [[:alpha:][:alnum:]]*.c foo1.c FNM_PERIOD 0
 [[:upper:]]* FOO NONE 0
index a9be5e26625f4fd97de0551ec7e3a34ab792cc12..0c966fe7c3b60d1bb29963eaef037d7c872d367c 100644 (file)
@@ -14,7 +14,7 @@
 #ifdef HAVE_STRINGS_H
 # include <strings.h>
 #endif /* HAVE_STRINGS_H */
-#ifdef HAVE_GLOB
+#ifdef HAVE_EXTENDED_GLOB
 # include <glob.h>
 #else
 # include "compat/glob.h"
@@ -176,7 +176,8 @@ main(int argc, char **argv)
 int test_glob(struct gl_entry *entry)
 {
        glob_t gl;
-       int i = 0;
+       char **ap;
+       int nmatches = 0, i = 0;
 
        if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) {
                fprintf(stderr, "glob failed: %s: %s\n", entry->pattern,
@@ -184,21 +185,29 @@ int test_glob(struct gl_entry *entry)
                exit(1);
        }
 
-       if (gl.gl_matchc != entry->nresults)
+       for (ap = gl.gl_pathv; *ap != NULL; ap++)
+               nmatches++;
+
+       if (nmatches != entry->nresults)
                goto mismatch;
 
-       for (i = 0; i < gl.gl_matchc; i++) {
+       for (i = 0; i < entry->nresults; i++) {
                if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0)
                        goto mismatch;
                free(entry->results[i]);
        }
        return 0;
  mismatch:
-       fprintf(stderr, "globtest: mismatch for pattern %s, flags 0x%x "
-           "(found \"%s\", expected \"%s\")\n", entry->pattern, entry->flags,
-           gl.gl_pathv[i], entry->results[i]);
-       while (i < gl.gl_matchc) {
-               free(entry->results[i++]);
+       if (nmatches != entry->nresults) {
+               fprintf(stderr,
+                   "globtest: mismatch in number of results (found %d, expected %d) for pattern %s\n",
+                   nmatches, entry->nresults, entry->pattern);
+       } else {
+               fprintf(stderr, "globtest: mismatch for pattern %s, flags 0x%x "
+                   "(found \"%s\", expected \"%s\")\n", entry->pattern, entry->flags,
+                   gl.gl_pathv[i], entry->results[i]);
+               while (i < entry->nresults)
+                       free(entry->results[i++]);
        }
        return 1;
 }