Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [pushed] [gdb/build] Fix Wmaybe-uninitialized in gdb/windows-nat.c
Date: Wed,  4 Nov 2026 09:16:39 +0100	[thread overview]
Message-ID: <20261104081639.3700906-1-tdevries@suse.de> (raw)

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


                 reply	other threads:[~2026-11-04  8:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261104081639.3700906-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox