[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] only use legitimate shift counts in bitmap shifting



commit cc01bd72a1ce1170d15e2b6edd888781ffee8596
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Wed Apr 23 15:07:55 2014 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Wed Apr 23 15:07:55 2014 +0200

    only use legitimate shift counts in bitmap shifting
    
    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@xxxxxxxx>
    Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 xen/common/bitmap.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c
index 67dfd00..61d1ea4 100644
--- a/xen/common/bitmap.c
+++ b/xen/common/bitmap.c
@@ -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;
        }
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.