Received: from eggs.gnu.org ([2001:4830:134:3::10]:47027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmeKM-0000j5-Ji for qemu-devel@nongnu.org; Wed, 21 Sep 2016 06:00:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmeKI-0000Vb-4v for qemu-devel@nongnu.org; Wed, 21 Sep 2016 06:00:29 -0400 Received: from mail-sn1nam02on0125.outbound.protection.outlook.com ([104.47.36.125]:57418 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmeKH-0000VQ-Pj for qemu-devel@nongnu.org; Wed, 21 Sep 2016 06:00:26 -0400 From: Felipe Franciosi Date: Wed, 21 Sep 2016 10:00:23 +0000 Message-ID: References: <1474391326-871-1-git-send-email-felipe@nutanix.com> <000301d213c7$7142f980$53c8ec80$@ru> <87y42l93dr.fsf@dusky.pond.sub.org> In-Reply-To: <87y42l93dr.fsf@dusky.pond.sub.org> Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: <444D85D3CF0E754F95C136FC96E58855@namprd02.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Pavel Dovgalyuk , Pavel Dovgalyuk , Eric Blake , qemu-devel > On 21 Sep 2016, at 07:24, Markus Armbruster wrote: >=20 > "Pavel Dovgalyuk" writes: >=20 >>> From: Felipe Franciosi [mailto:felipe@nutanix.com] >>> If compiling with -Werror=3Dunused-result, replay-internal.c won't buil= d >>> due to a call to fwrite() where the returned value is ignored. A simple >>> cast to (void) is not sufficient on recent GCCs, so this fixes it. >>>=20 >>> Signed-off-by: Felipe Franciosi >>> --- >>> replay/replay-internal.c | 2 +- >>> 1 file changed, 1 insertion(+), 1 deletion(-) >>>=20 >>> diff --git a/replay/replay-internal.c b/replay/replay-internal.c >>> index 5835e8d..6978d76 100644 >>> --- a/replay/replay-internal.c >>> +++ b/replay/replay-internal.c >>> @@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size= ) >>> { >>> if (replay_file) { >>> replay_put_dword(size); >>> - fwrite(buf, 1, size, replay_file); >>> + (void)(fwrite(buf, 1, size, replay_file)+1); >>> } >>> } >>=20 >> This looks very weird. Oh I couldn't agree more. I hate this syntax. It is, however, the simplest = way to get around this issue. See: http://stackoverflow.com/questions/11888594/ignoring-return-values-in-c That doesn't mean we should do it. I actually rather we didn't. :) I sent this patch to discuss how the maintainers feel about it given no one= bumped into this yet (apparently). >> I think it would be better to check the return value and stop >> the simulation in case of error. We can also make replay_put_array() return an int indicating whether an err= or occurred. The callers can then decide whether to care or not. I'll send = a v2 doing that instead for comments. > Ignoring errors is wrong more often than not. Whether it's wrong in > this case I can't say. True that. That's why I think a better first step is to make functions that= can fail return an error code. Callers can make that decision later. Unfor= tunately, glibc decided that fwrite() should be tagged with WUR and that tr= iggers this build failure. > What I can say is 1. the commit message needs to > explain *why* the error can be ignored, The error is already ignored today. I'll send a v2 that makes replay_put_ar= ray() reflect the error, the callers can then decide to ignore it. > and 2. the way you ignore the > error is scandalously ugly :) Oh we all agree on that. :-D > You say gcc doesn't honor the traditional > cast to void anymore. What's the exact error message you see? See this (lengthly discussion) for more details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D25509 Thanks, Felipe