[PATCH] canonicalize: Initialize 'dest' pointer in 'realpath_stk' [BZ #32577]
Nikhil R
nikhilar2410@gmail.com
Mon Jan 20 09:24:40 GMT 2025
From: Nikhil R <nikhilr5@kpit.com>
Fixes a GCC warning when compiling with the '-Os' optimization flag:
| canonicalize.c: In function 'realpath_stk':
| canonicalize.c:424:50: error: 'dest' may be used uninitialized in this function [-Werror=maybe-uninitialized]
| 424 | return scratch_buffer_dupfree (rname_buf, dest - rname);
The `dest` pointer is now explicitly initialized to ensure
it is not used uninitialized, preventing potential undefined
behavior and eliminating the warning.
Signed-off-by: Nikhil R <nikhilr5@kpit.com>
---
stdlib/canonicalize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c
index 528bf49acf..546c7b920c 100644
--- a/stdlib/canonicalize.c
+++ b/stdlib/canonicalize.c
@@ -187,7 +187,7 @@ struct realpath_bufs
static char *
realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs)
{
- char *dest;
+ char *dest = NULL;
char const *start;
char const *end;
int num_links = 0;
--
2.17.1
More information about the Libc-alpha
mailing list