public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/glob: initialize back_str to silence uninitialized variable warning
@ 2026-03-12 21:52 Josh Law
  2026-03-12 22:46 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Josh Law @ 2026-03-12 21:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Josh Law

From: Josh Law <objecting@objecting.org>

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.

Signed-off-by: Josh Law <objecting@objecting.org>
---
 lib/glob.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/glob.c b/lib/glob.c
index 69311568ad3d..7aca76c25bcb 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -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
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib/glob: initialize back_str to silence uninitialized variable warning
  2026-03-12 21:52 [PATCH] lib/glob: initialize back_str to silence uninitialized variable warning Josh Law
@ 2026-03-12 22:46 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2026-03-12 22:46 UTC (permalink / raw)
  To: Josh Law; +Cc: linux-kernel, Josh Law

On Thu, 12 Mar 2026 21:52:49 +0000 Josh Law <hlcj1234567@gmail.com> wrote:

> 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.
> 
> ...
>
> --- a/lib/glob.c
> +++ b/lib/glob.c
> @@ -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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-12 22:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-12 21:52 [PATCH] lib/glob: initialize back_str to silence uninitialized variable warning Josh Law
2026-03-12 22:46 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox