]> git.proxmox.com Git - mirror_qemu.git/commitdiff
spapr_drc: Fix potential undefined behaviour
authorDavid Gibson <david@gibson.dropbear.id.au>
Thu, 3 Sep 2015 00:08:23 +0000 (10:08 +1000)
committerDavid Gibson <david@gibson.dropbear.id.au>
Wed, 23 Sep 2015 00:51:09 +0000 (10:51 +1000)
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

index ee874326eee732e8a300aecc231999e45f1d8963..8cbcf4d346248cf3dd6fe8ae00ac4c280c0887e1 100644 (file)
@@ -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)
 {