lib/glob: initialize back_str to silence uninitialized variable warning
PATCH 1/1 lib/glob: initialize back_str to silence uninitialized variable warning
From: Josh Law <[email protected]>
back_str is only used when back_pat is non-NULL, and both are always set together, so it is safe in practice. Initialize back_str to NULL to make this safety invariant explicit and silence compiler/static analysis warnings.
--- lib/glob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/glob.c +1 -1
@@ -47,7 +47,7 @@ bool __pure glob_match(char const *pat, char const *str)* (no exception for /), it can be easily proved that there's * never a need to backtrack multiple levels. */ -char const *back_pat =NULL , *back_str; +char const *back_pat =NULL , *back_str =NULL ;/* * Loop over each token (character or class) in pat, matching
Signature · 1 line
2.34.1
Andrew Morton
maintainerQuoted 10 lines · On Thu, 12 Mar 2026 21:52:49 +0000 Josh Law <[email protected]> wrote:
back_stris only used whenback_patis non-NULL, and both are always set together, so it is safe in practice. Initializeback_strto NULL to make this safety invariant explicit and silence compiler/static analysis warnings....
lib/glob.c bool __pure glob_match(char const *pat, char const *str) · line 51
Quoted 6 lines
lib/glob.c +1
-1@@ -47,7 +47,7 @@ bool __pure glob_match(char const *pat, char const *str)* (no exception for /), it can be easily proved that there's * never a need to backtrack multiple levels. */ -char const *back_pat =NULL , *back_str; +char const *back_pat =NULL , *back_str =NULL ;
I can certainly believe that some compiler versions will warn about this, but please always quote the warning/error message when fixing such things.