Received: from eggs.gnu.org ([140.186.70.92]:52314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJh36-0006Wo-NC for qemu-devel@nongnu.org; Fri, 28 Oct 2011 03:40:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJh35-0007Tp-CS for qemu-devel@nongnu.org; Fri, 28 Oct 2011 03:40:20 -0400 From: Markus Armbruster References: <1319487523-19978-1-git-send-email-sw@weilnetz.de> <20111026125431.GC27267@stefanha-thinkpad.localdomain> Date: Fri, 28 Oct 2011 09:40:06 +0200 In-Reply-To: <20111026125431.GC27267@stefanha-thinkpad.localdomain> (Stefan Hajnoczi's message of "Wed, 26 Oct 2011 13:54:31 +0100") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH] Fix compiler warning (always return a value) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: qemu-trivial@nongnu.org, Stefan Weil , qemu-devel@nongnu.org Stefan Hajnoczi writes: > 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 >> --- >> 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. Why is it useful to make failed assertions stop the program regardless of NDEBUG only when the assertion happens to be "can't reach"? If you worry about assertions failing, don't compile with -DNDEBUG. "Doctor, it hurts when I disable assertions!" "Don't disable them, then." ;-P