]> Cypherpunks repositories - gostls13.git/commitdiff
liblink, cmd/gc: resolve several shift warnings
authorDave Cheney <dave@cheney.net>
Wed, 18 Dec 2013 23:34:33 +0000 (10:34 +1100)
committerDave Cheney <dave@cheney.net>
Wed, 18 Dec 2013 23:34:33 +0000 (10:34 +1100)
Address several warnings generated by clang -fsanitize=undefined

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/43050043

src/cmd/gc/bv.c
src/liblink/objfile.c
src/liblink/pcln.c

index 847e777eeae86edcb3312b9f11c287ec5e139b15..8c0e7a908eeddb1f90998e7d48c18b36c09a6672 100644 (file)
@@ -98,7 +98,7 @@ bvget(Bvec *bv, int32 i)
 
        if(i < 0 || i >= bv->n)
                fatal("bvget: index %d is out of bounds with length %d\n", i, bv->n);
-       mask = 1 << (i % WORDBITS);
+       mask = 1U << (i % WORDBITS);
        word = bv->b[i / WORDBITS] & mask;
        return word ? 1 : 0;
 }
index 6fdd8a9682e1a751b908a512176773d6ca963906..ba4087f07552050752aefd46b420ef229eeebd14 100644 (file)
@@ -371,7 +371,7 @@ wrint(Biobuf *b, int64 sval)
        uint64 uv, v;
        uchar buf[10], *p;
 
-       uv = (uint64)(sval<<1) ^ (uint64)(int64)(sval>>63);
+       uv = ((uint64)sval<<1) ^ (uint64)(int64)(sval>>63);
 
        p = buf;
        for(v = uv; v >= 0x80; v >>= 7)
@@ -634,7 +634,7 @@ rdint(Biobuf *f)
                        break;
        }
 
-       return (int64)(uv>>1) ^ ((int64)uv<<63>>63);
+       return (int64)(uv>>1) ^ ((int64)((uint64)uv<<63)>>63);
 }
 
 static char*
index 28cff903267982a948c9626d0cf3da3ead2d1571..62c0e8501f4398d2f7749fdaaf1b33eaed48cc89 100644 (file)
@@ -313,7 +313,7 @@ getvarint(uchar **pp)
        v = 0;
        p = *pp;
        for(shift = 0;; shift += 7) {
-               v |= (*p & 0x7F) << shift;
+               v |= (uint32)(*p & 0x7F) << shift;
                if(!(*p++ & 0x80))
                        break;
        }