From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T2NPf-0000bx-IJ for qemu-devel@nongnu.org; Fri, 17 Aug 2012 10:20:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T2NPe-0001cc-CK for qemu-devel@nongnu.org; Fri, 17 Aug 2012 10:20:35 -0400 Date: Fri, 17 Aug 2012 11:21:11 -0300 From: Luiz Capitulino Message-ID: <20120817112111.1231d0f6@doriath.home> In-Reply-To: <87obm9mwxn.fsf@blackfin.pond.sub.org> References: <1345210444-2292-1-git-send-email-sw@weilnetz.de> <87obm9mwxn.fsf@blackfin.pond.sub.org> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] monitor: Fix warning from clang List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-trivial@nongnu.org, Stefan Weil , qemu-devel@nongnu.org On Fri, 17 Aug 2012 16:10:12 +0200 Markus Armbruster wrote: > Stefan Weil writes: > > > ccc-analyzer reports these warnings: > > > > monitor.c:3532:21: warning: Division by zero > > val %= val2; > > ^ > > monitor.c:3530:21: warning: Division by zero > > val /= val2; > > ^ > > > > Rewriting the code fixes this (and also a style issue). > > I'm afraid this doesn't actually fix anything, because... > > > Signed-off-by: Stefan Weil > > --- > > monitor.c | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/monitor.c b/monitor.c > > index 0c34934..0ea2c14 100644 > > --- a/monitor.c > > +++ b/monitor.c > > @@ -3524,12 +3524,13 @@ static int64_t expr_prod(Monitor *mon) > > break; > > case '/': > > case '%': > > - if (val2 == 0) > > + if (val2 == 0) { > > expr_error(mon, "division by zero"); > > - if (op == '/') > > + } else if (op == '/') { > > val /= val2; > > - else > > + } else { > > val %= val2; > > + } > > break; > > } > > } > > ... expr_error() longjmp()s out. The expression evaluator commonly > exploits that. And that's correct. As far far I understood it's fixing clang, not qemu. > If expr_error() returned, the code would be just as wrong after your > patch as before. Hmm, how? It checks for val2 == 0 first. > Perhaps the checker can be shut up by making expr_error() QEMU_NORETURN. That's indeed a better solution.