From 550105b77914a8b06498318775b28e85c610b9a3 Mon Sep 17 00:00:00 2001 From: Christian Biesinger Date: Tue, 27 Aug 2019 13:22:38 -0500 Subject: [PATCH] Fix compiler warning in linux-namespaces.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ../../gdb/nat/linux-namespaces.c: In function ‘void mnsh_main(int)’: ../../gdb/nat/linux-namespaces.c:604:8: warning: ‘fd’ may be used uninitialized in this function [-Wmaybe-uninitialized] close (fd); ~~~~~~^~~~ And the warning is correct -- mnsh_recv_message can return -1 and leave fd uninitialized, and mnsh_main will still call close (fd) if that happens. Initialize fd to -1 to avoid that. gdb/ChangeLog: 2019-08-27 Christian Biesinger * nat/linux-namespaces.c (mnsh_main): Initialize fd (to -1). --- gdb/ChangeLog | 4 ++++ gdb/nat/linux-namespaces.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c7d2dae4ffa..002825312c3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2019-08-27 Christian Biesinger + + * nat/linux-namespaces.c (mnsh_main): Initialize fd (to -1). + 2019-08-27 Andrew Burgess * cli/cli-utils.c (info_print_options_defs): Delete. diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c index 503f755903c..e49bc1ade36 100644 --- a/gdb/nat/linux-namespaces.c +++ b/gdb/nat/linux-namespaces.c @@ -562,7 +562,7 @@ mnsh_main (int sock) while (1) { enum mnsh_msg_type type; - int fd, int1, int2; + int fd = -1, int1, int2; char buf[PATH_MAX]; ssize_t size, response = -1; -- 2.30.2