[binutils-gdb] [gdb/build] Fix Wmaybe-uninitialized in gdb/windows-nat.c
Tom de Vries
vries@sourceware.org
Wed Nov 4 08:16:21 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3d186a654a2f4f51c765eb54d2ceffbf09a9d9ee
commit 3d186a654a2f4f51c765eb54d2ceffbf09a9d9ee
Author: Tom de Vries <tdevries@suse.de>
Date: Wed Nov 4 09:16:16 2026 +0100
[gdb/build] Fix Wmaybe-uninitialized in gdb/windows-nat.c
With a --host=x86_64-w64-mingw32 cross-build on x86_64-linux using gcc 13.2.0,
I run into:
...
gdb/windows-nat.c: In member function 'virtual void \
windows_nat_target::create_inferior(...)':
gdb/windows-nat.c:3180:26: warning: 'shell' may be used uninitialized \
[-Wmaybe-uninitialized]
3180 | if (useshell && shell[0] != '\0')
| ~~~~~~~^
gdb/windows-nat.c:2882:8: note: 'shell' declared here
2882 | char shell[__PMAX]; /* Path to shell */
| ^~~~~
...
The warning is triggered by this code (showing the !__CYGWIN__ case):
...
static bool useshell = false;
void
windows_nat_target::create_inferior (...)
{
char shell[__PMAX]; /* Path to shell */
if (useshell && shell[0] != '\0')
windows_process->saw_create = -1;
...
}
...
and it's a false positive.
Indeed the shell variable is uninitialized, but it's also unused, because for
!__CYGWIN__, useshell is always false.
Make this explicit using constexpr.
This also fixes the warning.
Diff:
---
gdb/windows-nat.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 630bbf93f31..6f0fa890b8a 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -289,12 +289,19 @@ bool debug_memory = false; /* show target memory accesses */
bool debug_exceptions = false; /* show target exceptions */
/* User options. */
+
static bool new_console = false;
#ifdef __CYGWIN__
static bool cygwin_exceptions = false;
#endif
static bool new_group = true;
-static bool useshell = false; /* use shell for subprocesses */
+
+/* Use shell for subprocesses. */
+#ifdef __CYGWIN__
+static bool useshell = false;
+#else
+static constexpr bool useshell = false;
+#endif
/* See windows_nat_target::resume to understand why this is commented
out. */
More information about the Gdb-cvs
mailing list