Avoid undefined behavior of signed integer overflow; fix #3728

This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-07-05 02:48:00 +09:00
parent c6bd8ceab7
commit c377d504f6
+2 -2
View File
@@ -1521,13 +1521,13 @@ mrb_str_hash(mrb_state *mrb, mrb_value str)
struct RString *s = mrb_str_ptr(str);
mrb_int len = RSTR_LEN(s);
char *p = RSTR_PTR(s);
mrb_int key = 0;
uint64_t key = 0;
while (len--) {
key = key*65599 + *p;
p++;
}
return key + (key>>5);
return (mrb_int)(key + (key>>5));
}
/* 15.2.10.5.20 */