Message ID | 20190827182508.138503-1-cbiesinger@google.com |
---|---|
State | New, archived |
Headers |
Received: (qmail 20654 invoked by alias); 27 Aug 2019 18:25:13 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 20213 invoked by uid 89); 27 Aug 2019 18:25:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=fd, H*MI:google X-HELO: mail-qt1-f201.google.com Received: from mail-qt1-f201.google.com (HELO mail-qt1-f201.google.com) (209.85.160.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Aug 2019 18:25:11 +0000 Received: by mail-qt1-f201.google.com with SMTP id e22so21683268qtp.9 for <gdb-patches@sourceware.org>; Tue, 27 Aug 2019 11:25:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=mqrtuoSj+YhvJw5z3wpldy7+ppZVG4i9Q03NzO06cpU=; b=vUAT3ghpGzb+b0cNsMuIK+SZA/Ym6/U/J6mQhI60KN66eatkfS/gUrhJOGTYUWUtgy 8ABnajnh7vs6hM7ep0URoXdtjVe15Ckg5W+fC+5XB7+cT84qaENlF8mXbmfFvZ4gcd9E kzsYRthvpw2O0vVMAOyow5VfVtXqco3NgI3evNJRJwRjhOQBe1g3A9r3EyiK21VSvqO9 BUGa/hZL7p4GQjgaCLS0lz94Ufgz95Dxi2ajTsSNBAPLqxte5mTtWZdQZgnsyCAPfQFw ZTKpoflFnxtKdqCvX8fnCdfej9RKYXq6OmxwVp8GG9WpvPKcb0V9OypVi46i4nik6lOe bWNA== Date: Tue, 27 Aug 2019 13:25:08 -0500 Message-Id: <20190827182508.138503-1-cbiesinger@google.com> Mime-Version: 1.0 Subject: [PATCH] Fix compiler warning in linux-namespaces.c From: "Christian Biesinger via gdb-patches" <gdb-patches@sourceware.org> Reply-To: Christian Biesinger <cbiesinger@google.com> To: gdb-patches@sourceware.org Cc: Christian Biesinger <cbiesinger@google.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes |
Commit Message
Terekhov, Mikhail via Gdb-patches
Aug. 27, 2019, 6:25 p.m. UTC
../../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 <cbiesinger@google.com> * nat/linux-namespaces.c (mnsh_main): Initialize fd (to -1). --- gdb/nat/linux-namespaces.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Tuesday, August 27 2019, Christian Biesinger via gdb-patches wrote: > ../../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. Thanks. IMO this patch could be treated as obvious. > gdb/ChangeLog: > > 2019-08-27 Christian Biesinger <cbiesinger@google.com> > > * nat/linux-namespaces.c (mnsh_main): Initialize fd (to -1). > --- > gdb/nat/linux-namespaces.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c > index 503f755903..57843cda36 100644 > --- a/gdb/nat/linux-namespaces.c > +++ b/gdb/nat/linux-namespaces.c > @@ -562,14 +562,14 @@ 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; > > size = mnsh_recv_message (sock, &type, > &fd, &int1, &int2, > buf, sizeof (buf)); > - > +` This seems like a typo. > if (size >= 0 && size < sizeof (buf)) > { > switch (type) > -- > 2.23.0.187.g17f5b7556c-goog Cheers,
On Tue, Aug 27, 2019 at 1:42 PM Sergio Durigan Junior <sergiodj@redhat.com> wrote: > > On Tuesday, August 27 2019, Christian Biesinger via gdb-patches wrote: > > > ../../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. > > Thanks. IMO this patch could be treated as obvious. Thanks, fixed the typo below and pushed as obvious. > > gdb/ChangeLog: > > > > 2019-08-27 Christian Biesinger <cbiesinger@google.com> > > > > * nat/linux-namespaces.c (mnsh_main): Initialize fd (to -1). > > --- > > gdb/nat/linux-namespaces.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c > > index 503f755903..57843cda36 100644 > > --- a/gdb/nat/linux-namespaces.c > > +++ b/gdb/nat/linux-namespaces.c > > @@ -562,14 +562,14 @@ 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; > > > > size = mnsh_recv_message (sock, &type, > > &fd, &int1, &int2, > > buf, sizeof (buf)); > > - > > +` > > This seems like a typo. > > > if (size >= 0 && size < sizeof (buf)) > > { > > switch (type) > > -- > > 2.23.0.187.g17f5b7556c-goog > > Cheers, > > -- > Sergio > GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36 > Please send encrypted e-mail if possible > http://sergiodj.net/
diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c index 503f755903..57843cda36 100644 --- a/gdb/nat/linux-namespaces.c +++ b/gdb/nat/linux-namespaces.c @@ -562,14 +562,14 @@ 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; size = mnsh_recv_message (sock, &type, &fd, &int1, &int2, buf, sizeof (buf)); - +` if (size >= 0 && size < sizeof (buf)) { switch (type)