]> xenbits.xensource.com Git - xen.git/commitdiff
only use legitimate shift counts in bitmap shifting
authorJan Beulich <jbeulich@suse.com>
Wed, 23 Apr 2014 13:07:55 +0000 (15:07 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 23 Apr 2014 13:07:55 +0000 (15:07 +0200)
For rem being zero (where rem is the remainder of a division by
BITS_PER_LONG), shifts by "BITS_PER_LONG - rem" degenerate to undefined
constructs.

An alternative would be to remove these implicitly unused functions.

Coverity ID 1192174 (__bitmap_shift_right)
Coverity ID 1192175 (__bitmap_shift_left)

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen/common/bitmap.c

index 67dfd001e6b38f8c0ba6e5eb248ca8cb9a07a379..61d1ea4eae25438f56dc2c0c7b5c462ba5f10af5 100644 (file)
@@ -144,7 +144,9 @@ void __bitmap_shift_right(unsigned long *dst,
                lower = src[off + k];
                if (left && off + k == lim - 1)
                        lower &= mask;
-               dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem;
+               dst[k] = rem
+                        ? (upper << (BITS_PER_LONG - rem)) | (lower >> rem)
+                        : lower;
                if (left && k == lim - 1)
                        dst[k] &= mask;
        }
@@ -185,7 +187,9 @@ void __bitmap_shift_left(unsigned long *dst,
                upper = src[k];
                if (left && k == lim - 1)
                        upper &= (1UL << left) - 1;
-               dst[k + off] = lower  >> (BITS_PER_LONG - rem) | upper << rem;
+               dst[k + off] = rem ? (lower >> (BITS_PER_LONG - rem))
+                                     | (upper << rem)
+                                  : upper;
                if (left && k + off == lim - 1)
                        dst[k + off] &= (1UL << left) - 1;
        }