summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-11-11 22:19:58 -0800
committerRuss Cox <rsc@golang.org>2009-11-11 22:19:58 -0800
commit028283d6f0a8b3509f8d54b9d068764935d99b6b (patch)
tree109d90991d619f6f6884b21370f35926f8a486b3
parent0faab40b7968a482c6b81cd5e4ca15e267ca6176 (diff)
downloadgolang-028283d6f0a8b3509f8d54b9d068764935d99b6b.tar.gz
gopack: work around gcc bug in hash function
Fixes issue 48. (this time for sure!) R=r, r1 http://codereview.appspot.com/152088
-rw-r--r--src/cmd/gopack/ar.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/cmd/gopack/ar.c b/src/cmd/gopack/ar.c
index d8f2d4800..dfe202492 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