From patchwork Tue Jul 12 06:48:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 9224655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 893A6604DB for ; Tue, 12 Jul 2016 06:49:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E72527EED for ; Tue, 12 Jul 2016 06:49:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 622A827F94; Tue, 12 Jul 2016 06:49:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7AE327EED for ; Tue, 12 Jul 2016 06:49:07 +0000 (UTC) Received: from localhost ([::1]:37880 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMrVB-00065D-S8 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Jul 2016 02:49:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMrUv-000658-49 for qemu-devel@nongnu.org; Tue, 12 Jul 2016 02:48:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMrUp-0003to-1m for qemu-devel@nongnu.org; Tue, 12 Jul 2016 02:48:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMrUo-0003t3-ST for qemu-devel@nongnu.org; Tue, 12 Jul 2016 02:48:42 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BF1746203; Tue, 12 Jul 2016 06:48:41 +0000 (UTC) Received: from ad.usersys.redhat.com (dhcp-14-122.nay.redhat.com [10.66.14.122]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6C6mcxS001221; Tue, 12 Jul 2016 02:48:39 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Tue, 12 Jul 2016 14:48:33 +0800 Message-Id: <1468306113-847-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 12 Jul 2016 06:48:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] util: Fix MIN_NON_ZERO X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, Miroslav Rezanina , Peter Lieven , Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP MIN_NON_ZERO(0, 1) is evaluated to 0. Rewrite the macro to fix it. Reported-by: Miroslav Rezanina Signed-off-by: Fam Zheng Reviewed-by: Eric Blake --- include/qemu/osdep.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index e63da28..e4c6ae6 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -151,7 +151,8 @@ extern int daemon(int, int); /* Minimum function that returns zero only iff both values are zero. * Intended for use with unsigned values only. */ #ifndef MIN_NON_ZERO -#define MIN_NON_ZERO(a, b) (((a) != 0 && (a) < (b)) ? (a) : (b)) +#define MIN_NON_ZERO(a, b) ((a) == 0 ? (b) : \ + ((b) == 0 ? (a) : (MIN(a, b)))) #endif /* Round number down to multiple */