From: Todd C. Miller Date: Wed, 6 Apr 2011 19:13:23 +0000 (-0400) Subject: Stop testing unspecified behavior in fnmatch X-Git-Tag: SUDO_1_8_1~5^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60e9e4dd837470e957b1ea4fe68d9d9c021b8634;p=sudo Stop testing unspecified behavior in fnmatch Make glob test more portable --- diff --git a/compat/regress/fnmatch/fnm_test.in b/compat/regress/fnmatch/fnm_test.in index e19ec7df2..5d452efe2 100644 --- a/compat/regress/fnmatch/fnm_test.in +++ b/compat/regress/fnmatch/fnm_test.in @@ -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 diff --git a/compat/regress/glob/globtest.c b/compat/regress/glob/globtest.c index a9be5e266..0c966fe7c 100644 --- a/compat/regress/glob/globtest.c +++ b/compat/regress/glob/globtest.c @@ -14,7 +14,7 @@ #ifdef HAVE_STRINGS_H # include #endif /* HAVE_STRINGS_H */ -#ifdef HAVE_GLOB +#ifdef HAVE_EXTENDED_GLOB # include #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; }