[dpdk-dev] [PATCH] cmdline: fix warning for unused return value

Olivier MATZ olivier.matz at 6wind.com
Thu Sep 7 21:46:18 CEST 2017


On Thu, Sep 07, 2017 at 10:50:20AM -0700, Stephen Hemminger wrote:
> On Thu,  7 Sep 2017 14:09:23 +0100
> Bruce Richardson <bruce.richardson at intel.com> wrote:
> 
> > 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 <bruce.richardson at intel.com>
> > ---
> >  lib/librte_cmdline/cmdline.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
> > index a9c47be..d749165 100644
> > --- a/lib/librte_cmdline/cmdline.c
> > +++ b/lib/librte_cmdline/cmdline.c
> > @@ -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


More information about the dev mailing list