From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3Ig-0003v7-58 for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:21:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZX3Ib-0000HO-IK for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:21:46 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:35054) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZX3Ib-0000HE-DZ for qemu-devel@nongnu.org; Wed, 02 Sep 2015 04:21:41 -0400 Received: by pacfv12 with SMTP id fv12so3895453pac.2 for ; Wed, 02 Sep 2015 01:21:40 -0700 (PDT) References: <1441077438-24900-1-git-send-email-david@gibson.dropbear.id.au> From: Alexey Kardashevskiy Message-ID: <55E6B18E.2070207@ozlabs.ru> Date: Wed, 2 Sep 2015 18:21:34 +1000 MIME-Version: 1.0 In-Reply-To: <1441077438-24900-1-git-send-email-david@gibson.dropbear.id.au> Content-Type: text/plain; charset=koi8-r; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: David Gibson , peter.maydell@linaro.org, agraf@suse.de, benh@kernel.crashing.org Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org On 09/01/2015 01:17 PM, David Gibson wrote: > The DRC_INDEX_ID_MASK macro does a left shift on ~0, which is a signed > quantity, and therefore undefined behaviour according to the C spec. In > particular this causes warnings from the clang sanitizer. > > This fixes it by calculating the same mask without using ~0 (I think the > new method is a more common idiom for generating masks anyway). For good > measure I also use 1ULL to force the expression's type to unsigned long > long, which should be good for assigning to anything we're going to want > to. > > Reported-by: Peter Maydell > Signed-off-by: David Gibson Reviewed-by: Alexey Kardashevskiy > --- > hw/ppc/spapr_drc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > I'm hoping to get some Reviewed-bys for this patch so that I'm ready > to merge my spapr-next queue. > > diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c > index ee87432..8cbcf4d 100644 > --- a/hw/ppc/spapr_drc.c > +++ b/hw/ppc/spapr_drc.c > @@ -32,7 +32,7 @@ > > #define DRC_CONTAINER_PATH "/dr-connector" > #define DRC_INDEX_TYPE_SHIFT 28 > -#define DRC_INDEX_ID_MASK (~(~0 << DRC_INDEX_TYPE_SHIFT)) > +#define DRC_INDEX_ID_MASK ((1ULL << DRC_INDEX_TYPE_SHIFT) - 1) > > static sPAPRDRConnectorTypeShift get_type_shift(sPAPRDRConnectorType type) > { > -- Alexey