summaryrefslogtreecommitdiffstats
path: root/src/misc
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2016-04-30 10:40:54 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2016-04-30 10:40:54 -0700
commit2de8f04c0de744a3a3f0c04d9286c94a2154cc76 (patch)
tree1877d46bc6234bc081cf2138780b9228abfd0686 /src/misc
parent59f3389c9bce4c20c6476d46513883f0cf15e454 (diff)
downloadabc-2de8f04c0de744a3a3f0c04d9286c94a2154cc76.tar.gz
abc-2de8f04c0de744a3a3f0c04d9286c94a2154cc76.tar.bz2
abc-2de8f04c0de744a3a3f0c04d9286c94a2154cc76.zip
Suggested bug fix in st__strhash().
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/st/st.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/misc/st/st.c b/src/misc/st/st.c
index cbdac8be..b54509d6 100644
--- a/src/misc/st/st.c
+++ b/src/misc/st/st.c
@@ -448,14 +448,13 @@ int
int
st__strhash(const char *string, int modulus)
{
- int val = 0;
- int c;
-
- while ((c = *string++) != '\0') {
- val = val*997 + c;
+ unsigned char * ustring = (unsigned char *)string;
+ unsigned c, val = 0;
+ assert( modulus > 0 );
+ while ((c = *ustring++) != '\0') {
+ val = val*997 + c;
}
-
- return ((val < 0) ? -val : val)%modulus;
+ return (int)(val%modulus);
}
int