Fix subexpression widening in memhash() of disclaim_weakmap_test
authorIvan Maidanski <ivmai@mail.ru>
Wed, 21 Aug 2019 08:31:52 +0000 (11:31 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 21 Aug 2019 08:31:52 +0000 (11:31 +0300)
(fix of commit 0cc2c0e7e)

It would be more correct to widen the argument (from unsigned to
GC_word) of multiply operation instead of implicit widening of the
result.

* tests/disclaim_weakmap_test.c (memhash): Cast acc to GC_word before
multiplying by 2003; cast the whole expression to unsigned type (before
assigning it to acc).

tests/disclaim_weakmap_test.c

index cb6d050..516a3fd 100644 (file)
@@ -98,7 +98,7 @@ unsigned memhash(void *src, size_t len)
 
   my_assert(len % sizeof(GC_word) == 0);
   for (i = 0; i < len / sizeof(GC_word); ++i) {
-    acc = (2003 * acc + ((GC_word *)src)[i]) / 3;
+    acc = (unsigned)((2003 * (GC_word)acc + ((GC_word *)src)[i]) / 3);
   }
   return acc;
 }