diff options
author | Russ Cox <rsc@golang.org> | 2009-11-11 22:19:58 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-11-11 22:19:58 -0800 |
commit | 8b957209182a49c79db0bfc2387c44b0b7fa0e2d (patch) | |
tree | d7fbd3ad0a956cd74b8d333e246d35edcbf6f157 | |
parent | 0c83f23d44bd1679d5facb2428196551c0c2f7f6 (diff) | |
download | go-8b957209182a49c79db0bfc2387c44b0b7fa0e2d.tar.gz go-8b957209182a49c79db0bfc2387c44b0b7fa0e2d.zip |
gopack: work around gcc bug in hash function
Fixes #48. (this time for sure!)
R=r, r1
https://golang.org/cl/152088
-rw-r--r-- | src/cmd/gopack/ar.c | 13 |
1 files changed, 10 insertions, 3 deletions
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 |