[PATCH v3][BZ #10246] glob() with GLOB_NOCHECK is returning a modified pattern sometimes.
Ondřej Bílka
neleai@seznam.cz
Mon Oct 21 15:30:00 GMT 2013
On Mon, Oct 21, 2013 at 03:19:52PM +0200, OndÅej BÃlka wrote:
> On Mon, Oct 21, 2013 at 03:07:54PM +0200, OndÅej BÃlka wrote:
> > On Mon, Oct 21, 2013 at 11:49:33AM +0000, Joseph S. Myers wrote:
> > > This sounds like something for which it should be easy to add a testcase
> > > to the testsuite.
> > >
> > > --
> > Here.
> >
> Which still shows that pattern is modified, now question is where.
After bit of debugging it was caused by different part of code. I
skipped this in previous attemp because flags &= ~(GLOB_NOCHECK looked
like unconditional statement.
[BZ #10246]
* posix/glob.c (glob): Return correct value when GLOB_NOCHECK
is specified.
* posix/tst-gnuglob.c (main): Add testcase.
diff --git a/posix/glob.c b/posix/glob.c
index 85237c2..4b639b4 100644
--- a/posix/glob.c
+++ b/posix/glob.c
@@ -1188,10 +1188,12 @@ glob (pattern, flags, errfunc, pglob)
}
if (dirname_modified)
flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
- status = glob_in_dir (filename, dirname, flags, errfunc, pglob,
- alloca_used);
+ status = glob_in_dir (filename, dirname, flags & ~GLOB_NOCHECK,
+ errfunc, pglob, alloca_used);
if (status != 0)
{
+ if (status == GLOB_NOMATCH && flags & GLOB_NOCHECK)
+ goto no_matches;
if (status == GLOB_NOMATCH && flags != orig_flags
&& pglob->gl_pathc + pglob->gl_offs == oldcount)
{
diff --git a/posix/tst-gnuglob.c b/posix/tst-gnuglob.c
index 6e42724..89bd223 100644
--- a/posix/tst-gnuglob.c
+++ b/posix/tst-gnuglob.c
@@ -392,6 +392,14 @@ main (void)
memset (&gl, '\0', sizeof (gl));
+ glob ("//foo", GLOB_NOCHECK, NULL, &gl);
+ printf ("results for glob (\"//foo\", 0)\n %s\n", gl.gl_pathv[0]);
+ if (strcmp(gl.gl_pathv[0],"//foo"))
+ {
+ printf ("failed\n");
+ result = 1;
+ }
+
gl.gl_closedir = my_closedir;
gl.gl_readdir = my_readdir;
gl.gl_opendir = my_opendir;
More information about the Libc-alpha
mailing list