From 55f5cf6686e2011d2ad778e53f1960ebc6a9f1bd Mon Sep 17 00:00:00 2001 From: "Bohao(Aaron) Wang" Date: Tue, 14 May 2019 14:14:56 -0400 Subject: [PATCH] Use unsigned integer for hashing algorithm The hashing function used signed intger for varaible hash and seed, which could lead to integer overflow. Fix the issue by changing the signed integer type to unsigned. Closes: #1794 Signed-off-by: Bohao(Aaron) Wang --- compiler/compile/OMRCompilation.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/compile/OMRCompilation.cpp b/compiler/compile/OMRCompilation.cpp index 1e07e9be195..894acac2b15 100644 --- a/compiler/compile/OMRCompilation.cpp +++ b/compiler/compile/OMRCompilation.cpp @@ -333,10 +333,10 @@ OMR::Compilation::Compilation( _adhocRandom = new (m->trHeapMemory()) TR_RandomGenerator(options.getRandomSeed()); if (options.getOption(TR_RandomSeedSignatureHash)) { - int32_t hash = 0; + uint32_t hash = 0; for (const char *c = self()->signature(); *c; c++) - hash = 33*hash + (int32_t)(*c); - int32_t seed = _options->getRandomSeed(); + hash = 33*hash + (uint32_t)(*c); + uint32_t seed = _options->getRandomSeed(); seed ^= hash; _primaryRandom->setSeed(seed); _adhocRandom->setSeed(_primaryRandom->getRandom());