From eec1c592ebd16eda3e4720da015b1c9479429a75 Mon Sep 17 00:00:00 2001 From: Kevin Langman Date: Thu, 2 Dec 2021 15:51:56 -0500 Subject: [PATCH] Prevent FPE in scaleSizeBasedOnBlockFrequency() float to int32 cast Prevent a FPE when casting a float that is larger then 0x7fffffff to an int32. Signed-off-by: Kevin Langman --- runtime/compiler/optimizer/InlinerTempForJ9.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/compiler/optimizer/InlinerTempForJ9.cpp b/runtime/compiler/optimizer/InlinerTempForJ9.cpp index 09b5df3ded4..8934b0c7365 100644 --- a/runtime/compiler/optimizer/InlinerTempForJ9.cpp +++ b/runtime/compiler/optimizer/InlinerTempForJ9.cpp @@ -4144,7 +4144,8 @@ int32_t TR_MultipleCallTargetInliner::scaleSizeBasedOnBlockFrequency(int32_t byt int adjFrequency = frequency ? frequency : 1; float factor = (float)adjFrequency / (float)maxFrequency; - bytecodeSize = (int32_t)((float)bytecodeSize / (factor*factor)); + float weight = (float)bytecodeSize / (factor*factor); + bytecodeSize = (weight > 0x7fffffff) ? 0x7fffffff : ((int32_t)weight); heuristicTrace(tracer(),"exceedsSizeThreshold: Scaled up size for call from %d to %d", oldSize, bytecodeSize); }