Jeremy Katz
2006-Apr-26 02:18 UTC
[Xen-devel] [PATCH] Check some returns of common functions
When building with FORTIFY_SOURCE to ensure that return codes of common functions are checked to avoid some bugs, a few warnings pop up and become errors due to -Werror. Attached checks the return codes Signed-off-by: Jeremy Katz <katzj@redhat.com> _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ewan Mellor
2006-Apr-26 08:29 UTC
Re: [Xen-devel] [PATCH] Check some returns of common functions
On Tue, Apr 25, 2006 at 10:18:04PM -0400, Jeremy Katz wrote:> When building with FORTIFY_SOURCE to ensure that return codes of common > functions are checked to avoid some bugs, a few warnings pop up and > become errors due to -Werror. Attached checks the return codes > > Signed-off-by: Jeremy Katz <katzj@redhat.com>> --- xen-unstable.hg/tools/xenstore/xenstored_core.c.unused 2006-04-25 22:06:11.000000000 -0400 > +++ xen-unstable.hg/tools/xenstore/xenstored_core.c 2006-04-25 22:11:22.000000000 -0400 > @@ -173,7 +173,7 @@ > va_list arglist; > char *str; > char sbuf[1024]; > - int ret; > + int ret, dummy; > > if (tracefd < 0) > return; > @@ -184,7 +184,7 @@ > va_end(arglist); > > if (ret <= 1024) { > - write(tracefd, sbuf, ret); > + dummy = write(tracefd, sbuf, ret); > return;Does (void)write(tracefd, sbuf, ref) not work? This ought to make it clear that the return value is being ignored without additional dummy variables. Ewan. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2006-Apr-26 08:52 UTC
Re: [Xen-devel] [PATCH] Check some returns of common functions
On 26 Apr 2006, at 09:29, Ewan Mellor wrote:> Does (void)write(tracefd, sbuf, ref) not work? This ought to make it > clear > that the return value is being ignored without additional dummy > variables.No. That would be too obvious and useful! The following might be clearer than doing the workaround in-place though: #define ignore_retval(x) do { long __r; __r = (long)(x); } while (0) (Most useful scalar types can be cast to/from long.) -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Aron Griffis
2006-Apr-26 19:02 UTC
Re: [Xen-devel] [PATCH] Check some returns of common functions
Keir Fraser wrote: [Wed Apr 26 2006, 04:52:16AM EDT]> The following might be clearer than doing the workaround in-place > though: > > #define ignore_retval(x) do { long __r; __r = (long)(x); } while (0)How is a custom wrapper clearer than (void), which is generally recognized as intentionally ignoring the return value? Aron _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2006-Apr-27 08:26 UTC
Re: [Xen-devel] [PATCH] Check some returns of common functions
On 26 Apr 2006, at 20:02, Aron Griffis wrote:>> The following might be clearer than doing the workaround in-place >> though: >> >> #define ignore_retval(x) do { long __r; __r = (long)(x); } while (0) > > How is a custom wrapper clearer than (void), which is generally > recognized as intentionally ignoring the return value?Good point, except that casting the result to void does not avoid the warning/error in this particular case so we have to pick a less attractive workaround. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel