* [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour
@ 2015-09-01 3:17 David Gibson
2015-09-02 8:21 ` Alexey Kardashevskiy
0 siblings, 1 reply; 2+ messages in thread
From: David Gibson @ 2015-09-01 3:17 UTC (permalink / raw)
To: peter.maydell, aik, agraf, benh; +Cc: qemu-ppc, qemu-devel, David Gibson
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>
---
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)
{
--
2.4.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour
2015-09-01 3:17 [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour David Gibson
@ 2015-09-02 8:21 ` Alexey Kardashevskiy
0 siblings, 0 replies; 2+ messages in thread
From: Alexey Kardashevskiy @ 2015-09-02 8:21 UTC (permalink / raw)
To: David Gibson, peter.maydell, agraf, benh; +Cc: qemu-ppc, qemu-devel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-09-02 8:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-01 3:17 [Qemu-devel] [RFC] spapr_drc: Fix potential undefined behaviour David Gibson
2015-09-02 8:21 ` Alexey Kardashevskiy
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).