Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean
From: David Laight
Date: Sun Mar 01 2026 - 17:05:25 EST
On Sun, 1 Mar 2026 11:25:42 -0800
Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Sun, 1 Mar 2026 15:21:42 +0000 Josh Law <hlcj1234567@xxxxxxxxx> wrote:
>
> > Using bitwise OR (|=) on a boolean variable is valid C, but replacing it with a direct logical assignment makes the intent clearer and appeases strict static analysis tools.
> >
>
> Fair enough.
It might even generate better code.
Compilers have been known to generate 'really crap code(tm)' for
boolean arithmetic.
David
>
> > --- a/lib/glob.c
> > +++ b/lib/glob.c
> > @@ -96,7 +96,8 @@ bool __pure glob_match(char const *pat, char const *str)
> > class += 2;
> > /* Any special action if a > b? */
> > }
> > - match |= (a <= c && c <= b);
> > + if (a <= c && c <= b)
> > + match = true;
> > } while ((a = *class++) != ']');
> >
> > if (match == inverted)
>
> But if we're concerned about bool abuse, what's this?
>
> bool match = false, inverted = (*pat == '!');
> char const *class = pat + inverted;
>
>