From 4988a45c0675409c1d4e3e0b313fcc1f721843c8 Mon Sep 17 00:00:00 2001 From: Paulo Matos Date: Wed, 5 Jun 2019 22:49:55 +0200 Subject: [PATCH] Make variables unsigned to avoid ub in calculation According to ubsan we get several times into undefined behaviour due to signed overflow: foreign.c:91:21: runtime error: signed integer overflow: 3291370622602663862 * 3 cannot be represented in type 'long int' This happens only when the symbol name is relatively large like as for the call: symhash (s=0x5555558caab8 "(cs)set_enable_object_backreferences") original commit: 1e1c91869443d8a22beeebfcbe6fa14f9c3e2a6e --- c/foreign.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c/foreign.c b/c/foreign.c index 9b9f11f2e8..5c1c2abb3d 100644 --- a/c/foreign.c +++ b/c/foreign.c @@ -85,7 +85,7 @@ static ptr bvstring(const char *s) { /* multiplier weights each character, h = n factors in the length */ static iptr symhash(s) const char *s; { - iptr n, h; + uptr n, h; h = n = strlen(s); while (n--) h = h * multiplier + *s++;