Skip to content

Commit d802fd0

Browse files
marc-chevaliereme64
authored andcommitted
8352422: [ubsan] Out-of-range reported in ciMethod.cpp:917:20: runtime error: 2.68435e+09 is outside the range of representable values of type 'int'
Reviewed-by: epeter, dlong
1 parent 7d9a438 commit d802fd0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/hotspot/share/ci/ciMethod.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,14 @@ int ciMethod::scale_count(int count, float prof_factor) {
914914
method_life = counter_life;
915915
}
916916
if (counter_life > 0) {
917-
count = (int)((double)count * prof_factor * method_life / counter_life + 0.5);
918-
count = (count > 0) ? count : 1;
917+
double count_d = (double)count * prof_factor * method_life / counter_life + 0.5;
918+
if (count_d >= static_cast<double>(INT_MAX)) {
919+
// Clamp in case of overflowing int range.
920+
count = INT_MAX;
921+
} else {
922+
count = int(count_d);
923+
count = (count > 0) ? count : 1;
924+
}
919925
} else {
920926
count = 1;
921927
}

0 commit comments

Comments
 (0)