]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
src: Use 1U for bit shifting
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 14 Jun 2021 10:46:58 +0000 (12:46 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 14 Jun 2021 12:16:54 +0000 (14:16 +0200)
In a few places we take 1 and shift it left repeatedly. So much
that it won't longer fit into signed integer. The problem is that
this is undefined behaviour. Switching to 1U makes us stay within
boundaries.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
src/conf/domain_capabilities.h
src/cpu/cpu_x86.c

index 69e90893cc3af41c7b87612492a1744a024235c7..b6433b20c9c86cb95d0f13cc15d5e272ae10325c 100644 (file)
@@ -231,7 +231,7 @@ virDomainCapsCPUModelsGet(virDomainCapsCPUModels *cpuModels,
                           const char *name);
 
 #define VIR_DOMAIN_CAPS_ENUM_IS_SET(capsEnum, value) \
-    ((capsEnum).values & (1 << value))
+    ((capsEnum).values & (1U << value))
 
 #define VIR_DOMAIN_CAPS_ENUM_SET(capsEnum, ...) \
     do { \
index a4599499d04f2821cc20433594c2e6f4e0f67176..a4792c21dab3cb13b1b0763a2ab73660e55b0548 100644 (file)
@@ -2575,12 +2575,12 @@ cpuidSetLeafD(virCPUData *data,
     sub1 = *cpuid;
     for (sub = 2; sub < 64; sub++) {
         if (sub < 32 &&
-            !(sub0.eax & (1 << sub)) &&
-            !(sub1.ecx & (1 << sub)))
+            !(sub0.eax & (1U << sub)) &&
+            !(sub1.ecx & (1U << sub)))
             continue;
         if (sub >= 32 &&
-            !(sub0.edx & (1 << (sub - 32))) &&
-            !(sub1.edx & (1 << (sub - 32))))
+            !(sub0.edx & (1U << (sub - 32))) &&
+            !(sub1.edx & (1U << (sub - 32))))
             continue;
 
         cpuid->ecx_in = sub;
@@ -2614,7 +2614,7 @@ cpuidSetLeafResID(virCPUData *data,
         return -1;
 
     for (sub = 1; sub < 32; sub++) {
-        if (!(res & (1 << sub)))
+        if (!(res & (1U << sub)))
             continue;
         cpuid->ecx_in = sub;
         cpuidCall(cpuid);