Bug 162396

Summary: [libc] [patch] remove loop in globpexp1()@lib/libc/gen/glob.c
Product: Base System Reporter: Cheng-Lung Sung <clsung>
Component: kernAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me Keywords: patch
Priority: Normal    
Version: 8.2-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description Cheng-Lung Sung freebsd_committer freebsd_triage 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
Comment 2 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:38:41 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>