diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-07-05 02:48:00 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-07-05 03:11:39 +0900 |
| commit | c377d504f68e44f719f8314b1492b86409b1289c (patch) | |
| tree | c2b404beb2ef150e90456d2b754d6227d8ac08d1 /src/string.c | |
| parent | c6bd8ceab7244ef913dda99e678e1b97b8fe1a7a (diff) | |
| download | mruby-c377d504f68e44f719f8314b1492b86409b1289c.tar.gz mruby-c377d504f68e44f719f8314b1492b86409b1289c.zip | |
Avoid undefined behavior of signed integer overflow; fix #3728
Diffstat (limited to 'src/string.c')
| -rw-r--r-- | src/string.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/string.c b/src/string.c index e0b491bfb..bfa751332 100644 --- a/src/string.c +++ b/src/string.c @@ -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 */ |
