Skip to contentSkip to conversation

cmdline: fix warning for unused return value

PATCH Applied Bruce Richardson 5 participants 7 messages Sep 7, 2017 – Oct 5, 2017

lore
Share & tools
lore
#0 lore raw

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
index a9c47be..d749165 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw
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.

#3 lore raw
In reply to Bruce Richardson
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.

---
 lib/librte_cmdline/cmdline.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/librte_cmdline/cmdline.c +0 -0
index a9c47be..d749165 100644

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.

#4 lore raw
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.

---
 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
index a9c47be..d749165 100644
@@ -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

#5 lore raw
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.

---
 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
index a9c47be..d749165 100644
@@ -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
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 :-) )

Acked-by on v1 1/1
#6 lore raw
In reply to Bruce Richardson
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.

---

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
index a9c47be..d749165 100644
@@ -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

#2 lore raw
In reply to Olivier MATZ

07/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.

Applied, thanks