[ovs-dev] [PATCH] thread: Use explicit wide type when shifting > 32 bits

Thomas Graf tgraf at noironetworks.com
Fri Aug 29 10:21:49 UTC 2014


Without the explicit wide type, the shift operation may be performed
on a int which will result in implementation defined behaviour on a
system with more than 32 CPUs.

Signed-off-by: Thomas Graf <tgraf at noironetworks.com>
---
 lib/ovs-thread.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index fe6fb43..efbd60f 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -520,11 +520,11 @@ parse_cpuinfo(long int *n_cores)
                 break;
             }
 
-            if (cpu & (1 << id)) {
+            if (cpu & (1ULL << id)) {
                 /* We've already counted this package's cores. */
                 continue;
             }
-            cpu |= 1 << id;
+            cpu |= 1ULL << id;
 
             /* Find the number of cores for this package. */
             while (fgets(line, sizeof line, stream)) {
-- 
1.9.3




More information about the dev mailing list