Commit 2de8f04c by Alan Mishchenko

Suggested bug fix in st__strhash().

parent 59f3389c
...@@ -448,14 +448,13 @@ int ...@@ -448,14 +448,13 @@ int
int int
st__strhash(const char *string, int modulus) st__strhash(const char *string, int modulus)
{ {
int val = 0; unsigned char * ustring = (unsigned char *)string;
int c; unsigned c, val = 0;
assert( modulus > 0 );
while ((c = *string++) != '\0') { while ((c = *ustring++) != '\0') {
val = val*997 + c; val = val*997 + c;
} }
return (int)(val%modulus);
return ((val < 0) ? -val : val)%modulus;
} }
int int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment