cmdline: fix warning for unused return value
PATCH 1/1 cmdline: fix warning for unused return value
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from write() being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.
--- lib/librte_cmdline/cmdline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_cmdline/cmdline.c +2 -1
@@ -205,7 +205,8 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) }if (ret >=BUFSIZ ) ret =BUFSIZ -1 ; -write (cl->s_out, buf, ret); + ret =write (cl->s_out, buf, ret); + (void )ret;free (buf);#endif }
Signature · 1 line
2.7.4
Quoted 7 lines · Bruce Richardson
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from
write()being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.Signed-off-by Bruce Richardson <[email protected]>
Quoted 16 lines · On Thu, 7 Sep 2017 14:09:23 +0100 Bruce Richardson…
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from
write()being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.Signed-off-by Bruce Richardson <[email protected]>--- lib/librte_cmdline/cmdline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_cmdline/cmdline.c +0
-0
lib/librte_cmdline/cmdline.c cmdline_printf(const struct cmdline *cl, const char *fmt, ...) · line 209
Quoted 6 lines
lib/librte_cmdline/cmdline.c +2
-1@@ -205,7 +205,8 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) }if (ret >=BUFSIZ ) ret =BUFSIZ -1 ; -write (cl->s_out, buf, ret); + ret =write (cl->s_out, buf, ret); + (void )ret;
That is an ugly way to fix the warning.
If write fails, the user has probably logged out.
Quoted 14 lines · Stephen Hemminger
Quoted 11 lines · On Thu, 7 Sep 2017 14:09:23 +0100 Bruce Richardson…
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from
write()being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.Signed-off-by Bruce Richardson <[email protected]>--- lib/librte_cmdline/cmdline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
lib/librte_cmdline/cmdline.c cmdline_printf(const struct cmdline *cl, const char *fmt, ...) · line 209
Quoted 11 lines
lib/librte_cmdline/cmdline.c +2
-1@@ -205,7 +205,8 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) }if (ret >=BUFSIZ ) ret =BUFSIZ -1 ; -write (cl->s_out, buf, ret); + ret =write (cl->s_out, buf, ret); + (void )ret;That is an ugly way to fix the warning.
If write fails, the user has probably logged out.
Here, we are writing on stdout.
I don't think it's worst than calling printf() without checking the return value.
By the way, it looks strange to this code is compiled, because -D _GNU_SOURCE is passed to the compiler, and the code is:
#ifdef _GNU_SOURCE ... #else ... write() #endif
It does not mean we shouldn't fix it, but maybe it hides something else. Bruce, I bet you are testing your new build framework?
Olivier
Quoted 44 lines · Olivier MATZ
Quoted 14 lines · Stephen Hemminger
Quoted 11 lines · On Thu, 7 Sep 2017 14:09:23 +0100 Bruce Richardson…
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from
write()being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.Signed-off-by Bruce Richardson <[email protected]>--- lib/librte_cmdline/cmdline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 14 lines
lib/librte_cmdline/cmdline.c cmdline_printf(const struct cmdline *cl, const char *fmt, ...) · line 209
Quoted 11 lines
lib/librte_cmdline/cmdline.c +2
-1@@ -205,7 +205,8 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) }if (ret >=BUFSIZ ) ret =BUFSIZ -1 ; -write (cl->s_out, buf, ret); + ret =write (cl->s_out, buf, ret); + (void )ret;That is an ugly way to fix the warning.
If write fails, the user has probably logged out.Here, we are writing on stdout.
I don't think it's worst than callingprintf()without checking the return value.By the way, it looks strange to this code is compiled, because -D
_GNU_SOURCEis passed to the compiler, and the code is:#ifdef _GNU_SOURCE ... #else ... write() #endif
Quoted 4 lines
It does not mean we shouldn't fix it, but maybe it hides something else. Bruce, I bet you are testing your new build framework?
Olivier
Yep, and meson has the -Wunused-result flag on by default, and on Ubuntu write is marked as needing the result check. I don't like disabling warnings, so I'd rather fix it this way, for the sake of on extra line of ugliness. Open to better options though (other than not using Ubuntu, which is fine with me, but some others seem to object to that :-) )
Quoted 6 lines
From: dev [mailto:[email protected]] On Behalf Of Bruce Richardson
Sent: Thursday, September 7, 2017 2:09 PM
To: [email protected]
Cc: Richardson, Bruce <[email protected]>
Subject: [dpdk-dev] [PATCH] cmdline: fix warning for unused return value
Quoted 8 lines
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from
write()being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.Signed-off-by Bruce Richardson <[email protected]>---
A pragmatic fix for the compile warning at hand;
Quoted 20 lines
lib/librte_cmdline/cmdline.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)lib/librte_cmdline/cmdline.c +2
-1@@ -205,7 +205,8 @@ cmdline_printf(const struct cmdline *cl, const char *fmt, ...) }if (ret >=BUFSIZ ) ret =BUFSIZ -1 ; -write (cl->s_out, buf, ret); + ret =write (cl->s_out, buf, ret); + (void )ret;free (buf);#endif }
--
2.7.4
Thomas Monjalon
Applied07/09/2017 15:49, Olivier MATZ:
Quoted 10 lines · Bruce Richardson
Quoted 7 lines
When DPDK is compiled on Ubuntu with extra warnings turned on, there is a warning about the return value from
write()being unchecked. Rather than having builds disable the warning, which may mask other cases we do care about, we can add a dummy use of the return value in the code to silence it in this instance.Signed-off-by Bruce Richardson <[email protected]>Acked-by Olivier Matz <[email protected]>
Applied, thanks