Bug 162396 - [libc] [patch] remove loop in globpexp1()@lib/libc/gen/glob.c
Summary: [libc] [patch] remove loop in globpexp1()@lib/libc/gen/glob.c
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 8.2-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-09 05:10 UTC by Cheng-Lung Sung
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments
file.diff (2.42 KB, patch)
2011-11-09 05:10 UTC, Cheng-Lung Sung
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Cheng-Lung Sung freebsd_committer 2011-11-09 05:10:08 UTC
One can see that globexp1() is called with GLOB_BRACE.
    
In globexp1(), examine the pattern: 
    only "{}" => call glob0()
    no LBRACE => call glob0()
    with LBRACE => call globexp2 to deal with expression inside LBRACE

Take a look in glob0():
    glob0, return 0 if success, otherwise error (except GLOB_NOMATCH)
        => return err
        => return globextend()/GLOB_NOMATCH
        => return 0 

In globexp2()
    => non matched braces
        => call glob0(), return 0
    => matched brace-pair
        => parse brace
            => reach rbrace, call globexp1(), set return value to *rv

    set *rv = 0, return 0

*which implies always return 0 in globexp2*
As a result, the following code block in globexp1 can be reduced from:
-       while ((ptr = g_strchr(ptr, LBRACE)) != NULL)
-               if (!globexp2(ptr, pattern, pglob, &rv, limit))
-                       return rv;
to:
+       if ((ptr = g_strchr(ptr, LBRACE)) != NULL)
+               return globexp2(ptr, pattern, pglob, limit)


Besides, since *rv should indicate the acctual return value, the setting *rv = 0 and return 0 is ambiguous.
So the flow in globexp2() should be:

In globexp2()
    => non matched braces
        => call glob0(), return 0
    => matched brace-pair
        => parse brace
            => reach rbrace, call globexp1(), set return value to *rv
                => if success in glob0
                    return 0
                => if failed in glob0 (but not GLOB_NOMATCH)
                    return err
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:58:43 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped