From 2de8f04c0de744a3a3f0c04d9286c94a2154cc76 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sat, 30 Apr 2016 10:40:54 -0700 Subject: Suggested bug fix in st__strhash(). --- src/misc/st/st.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/misc') 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 -- cgit v1.2.3