]> Cypherpunks repositories - gostls13.git/commitdiff
gopack: work around gcc bug in hash function
authorRuss Cox <rsc@golang.org>
Thu, 12 Nov 2009 06:19:58 +0000 (22:19 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 12 Nov 2009 06:19:58 +0000 (22:19 -0800)
Fixes #48.  (this time for sure!)

R=r, r1
https://golang.org/cl/152088

src/cmd/gopack/ar.c

index d8f2d4800fa8448af6dddd1be22ad621cee50078..dfe2024922e98aaecbaf5842d6df69b2cad64a70 100644 (file)
@@ -784,9 +784,16 @@ hashstr(char *name)
        h = 0;
        for(cp = name; *cp; h += *cp++)
                h *= 1119;
-       if(h < 0)
-               h = ~h;
-       return h;
+       
+       // the code used to say
+       //      if(h < 0)
+       //              h = ~h;
+       // but on gcc 4.3 with -O2 on some systems,
+       // the if(h < 0) gets compiled away as not possible.
+       // use a mask instead, leaving plenty of bits but
+       // definitely not the sign bit.
+
+       return h & 0xfffffff;
 }
 
 int