From: Russ Cox Date: Thu, 12 Nov 2009 06:19:58 +0000 (-0800) Subject: gopack: work around gcc bug in hash function X-Git-Tag: weekly.2009-11-12~9 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8b957209182a49c79db0bfc2387c44b0b7fa0e2d;p=gostls13.git gopack: work around gcc bug in hash function Fixes #48. (this time for sure!) R=r, r1 https://golang.org/cl/152088 --- diff --git a/src/cmd/gopack/ar.c b/src/cmd/gopack/ar.c index d8f2d4800f..dfe2024922 100644 --- a/src/cmd/gopack/ar.c +++ b/src/cmd/gopack/ar.c @@ -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