Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [pushed] [gdb/build] Fix Wmaybe-uninitialized in gdb/windows-nat.c
@ 2026-11-04  8:16 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2026-11-04  8:16 UTC (permalink / raw)
  To: gdb-patches

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.
---
 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.  */

base-commit: e7467448fc657d4eb70865c787bfbcbc86026152
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-04  8:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04  8:16 [pushed] [gdb/build] Fix Wmaybe-uninitialized in gdb/windows-nat.c Tom de Vries

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