* [PATCH] Fix compiler warning in linux-namespaces.c
@ 2019-08-27 18:25 Christian Biesinger via gdb-patches
2019-08-27 18:42 ` Sergio Durigan Junior
0 siblings, 1 reply; 3+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-08-27 18:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Christian Biesinger
../../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(-)
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)
--
2.23.0.187.g17f5b7556c-goog
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix compiler warning in linux-namespaces.c
2019-08-27 18:25 [PATCH] Fix compiler warning in linux-namespaces.c Christian Biesinger via gdb-patches
@ 2019-08-27 18:42 ` Sergio Durigan Junior
2019-08-27 18:54 ` Christian Biesinger via gdb-patches
0 siblings, 1 reply; 3+ messages in thread
From: Sergio Durigan Junior @ 2019-08-27 18:42 UTC (permalink / raw)
To: Christian Biesinger via gdb-patches; +Cc: Christian Biesinger
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,
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] Fix compiler warning in linux-namespaces.c
2019-08-27 18:42 ` Sergio Durigan Junior
@ 2019-08-27 18:54 ` Christian Biesinger via gdb-patches
0 siblings, 0 replies; 3+ messages in thread
From: Christian Biesinger via gdb-patches @ 2019-08-27 18:54 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: Christian Biesinger via gdb-patches
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/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-08-27 18:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-27 18:25 [PATCH] Fix compiler warning in linux-namespaces.c Christian Biesinger via gdb-patches
2019-08-27 18:42 ` Sergio Durigan Junior
2019-08-27 18:54 ` Christian Biesinger via gdb-patches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox