qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: David Gibson <david@gibson.dropbear.id.au>,
	peter.maydell@linaro.org, agraf@suse.de,
	benh@kernel.crashing.org
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour
Date: Wed, 2 Sep 2015 18:21:34 +1000	[thread overview]
Message-ID: <55E6B18E.2070207@ozlabs.ru> (raw)
In-Reply-To: <1441077438-24900-1-git-send-email-david@gibson.dropbear.id.au>

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 <peter.maydell@linaro.org>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>	

> ---
>   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

      reply	other threads:[~2015-09-02  8:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-01  3:17 [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour David Gibson
2015-09-02  8:21 ` Alexey Kardashevskiy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55E6B18E.2070207@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=agraf@suse.de \
    --cc=benh@kernel.crashing.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).