Re: [PATCH 2/2] lib: glob: replace bitwise OR with logical operation on boolean

From: Andrew Morton

Date: Sun Mar 01 2026 - 14:25:51 EST


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.

> --- 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;