[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result
From: |
Felipe Franciosi |
Subject: |
Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result |
Date: |
Wed, 21 Sep 2016 10:12:37 +0000 |
> On 21 Sep 2016, at 11:07, Daniel P. Berrange <address@hidden> wrote:
>
> On Wed, Sep 21, 2016 at 10:00:23AM +0000, Felipe Franciosi wrote:
>>
>>> On 21 Sep 2016, at 07:24, Markus Armbruster <address@hidden> wrote:
>>>
>>> "Pavel Dovgalyuk" <address@hidden> writes:
>>>
>>>>> From: Felipe Franciosi [mailto:address@hidden
>>>>> If compiling with -Werror=unused-result, replay-internal.c won't build
>>>>> 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.
>>>>>
>>>>> Signed-off-by: Felipe Franciosi <address@hidden>
>>>>> ---
>>>>> replay/replay-internal.c | 2 +-
>>>>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>
>>>>> 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);
>>>>> }
>>>>> }
>>>>
>>>> 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
>
> If we want to ignore return value reliably, lets just pull in the
> ignore_value macro from gnulib which is known to work across GCC
> versions
I like that better. Do you want a series with a patch to add this macro to
include/qemu/compiler.h and another making replay_put_array() use it?
Cheers,
Felipe
>
>
> /* Normally casting an expression to void discards its value, but GCC
> versions 3.4 and newer have __attribute__ ((__warn_unused_result__))
> which may cause unwanted diagnostics in that case. Use __typeof__
> and __extension__ to work around the problem, if the workaround is
> known to be needed. */
> #if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
> # define ignore_value(x) \
> (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
> #else
> # define ignore_value(x) ((void) (x))
> #endif
>
> GNULIB makes it availavble under LGPLv2.1+
>
> eg used as:
>
> ignore_value(fwrite(buf, 1, size, replay_file));
>
> Regards,
> Daniel
> --
> |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
> |: http://libvirt.org -o- http://virt-manager.org :|
> |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
> |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
- [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Pavel Dovgalyuk, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Markus Armbruster, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Markus Armbruster, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Daniel P. Berrange, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Felipe Franciosi, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Markus Armbruster, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Eric Blake, 2016/09/21
- Re: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result, Daniel P. Berrange, 2016/09/22