aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2015-09-03 10:08:23 +1000
committerDavid Gibson <david@gibson.dropbear.id.au>2015-09-23 10:51:09 +1000
commit627c2ef7898794a28d706ecdf094491bebbb083a (patch)
tree0d53ae00210a3b7dd6451a799bbcfea25bf433b2
parentad440b4ae0727dbef5cace419d94d774de96886c (diff)
downloadqemu-627c2ef7898794a28d706ecdf094491bebbb083a.zip
qemu-627c2ef7898794a28d706ecdf094491bebbb083a.tar.gz
qemu-627c2ef7898794a28d706ecdf094491bebbb083a.tar.bz2
spapr_drc: Fix potential undefined behaviour
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>
-rw-r--r--hw/ppc/spapr_drc.c2
1 files changed, 1 insertions, 1 deletions
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)
{