[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), i
From: |
Alexander Graf |
Subject: |
Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), introduce qemu_abort? |
Date: |
Thu, 27 Oct 2011 10:24:23 +0200 |
On 26.10.2011, at 18:35, Stefan Weil <address@hidden> wrote:
> Am 26.10.2011 14:54, schrieb Stefan Hajnoczi:
>> On Mon, Oct 24, 2011 at 10:18:43PM +0200, Stefan Weil wrote:
>>> For compilations with -DNDEBUG, the default case did not return
>>> a value which caused a compiler warning.
>>>
>>> Signed-off-by: Stefan Weil <address@hidden>
>>> ---
>>> hw/ppce500_spin.c | 11 ++++++++---
>>> 1 files changed, 8 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/hw/ppce500_spin.c b/hw/ppce500_spin.c
>>> index cccd940..5b5ffe0 100644
>>> --- a/hw/ppce500_spin.c
>>> +++ b/hw/ppce500_spin.c
>>> @@ -168,17 +168,22 @@ static uint64_t spin_read(void *opaque,
>>> target_phys_addr_t addr, unsigned len)
>>> {
>>> SpinState *s = opaque;
>>> uint8_t *spin_p = &((uint8_t*)s->spin)[addr];
>>> + uint64_t result = 0;
>>>
>>> switch (len) {
>>> case 1:
>>> - return ldub_p(spin_p);
>>> + result = ldub_p(spin_p);
>>> + break;
>>> case 2:
>>> - return lduw_p(spin_p);
>>> + result = lduw_p(spin_p);
>>> + break;
>>> case 4:
>>> - return ldl_p(spin_p);
>>> + result = ldl_p(spin_p);
>>> + break;
>>> default:
>>> assert(0);
>>
>> I would replace assert(3) with abort(3). If this ever happens the
>> program is broken - returning 0 instead of an undefined value doesn't
>> help.
>>
>> Stefan
>
> Alex, do you agree on replacing assert() by abort()?
I honestly am pretty indifferent. IIRC I used assert(0) because it does show
you the line of code it failed in.
Alex
>
> I personally don't like abort() because it does not show the
> reason for the failure.
>
> Most users don't know how to get a core dump or how to
> use gdb. And even for those who know, a crash caused
> by an abort() which cannot be reproduced usually happens
> on a system were ulimit disables core dumps...
>
> I'd like to have a qemu_abort() macro in qemu-common.h which
> replaces all abort() calls used today:
>
> #define qemu_abort() \
> do { \
> fprintf(stderr, "QEMU aborted in %s, %s:%u\n", __func__, __FILE__,
> __LINE__);
> abort();
> } while (0)
>
> (The macro could also call a function which handles fprintf and abort).
>
> Cheers,
> Stefan W.
>
- [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Stefan Weil, 2011/10/24
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Stefan Hajnoczi, 2011/10/26
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), introduce qemu_abort?, Stefan Weil, 2011/10/26
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), introduce qemu_abort?, Blue Swirl, 2011/10/26
- [Qemu-devel] [RFC] Introduce qemu_abort? (was: Fix compiler warning (always return a value)), Stefan Weil, 2011/10/26
- Re: [Qemu-devel] [RFC] Introduce qemu_abort? (was: Fix compiler warning (always return a value)), Blue Swirl, 2011/10/26
- Re: [Qemu-devel] [RFC] Introduce qemu_abort? (was: Fix compiler warning (always return a value)), Peter Maydell, 2011/10/26
- Re: [Qemu-devel] [RFC] Introduce qemu_abort?, Markus Armbruster, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), introduce qemu_abort?, Stefan Hajnoczi, 2011/10/27
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), introduce qemu_abort?,
Alexander Graf <=
Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Markus Armbruster, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Stefan Hajnoczi, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Markus Armbruster, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Stefan Hajnoczi, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Markus Armbruster, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Stefan Hajnoczi, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Markus Armbruster, 2011/10/28
- Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value), Paolo Bonzini, 2011/10/28