Skip to content

Commit 9930d32

Browse files
github-actions[bot]Maoni0
andauthored
fix div by zero (#76334)
Co-authored-by: Maoni0 <maoni@microsoft.com>
1 parent 9c7b5a8 commit 9930d32

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,7 +3171,8 @@ gc_heap::dt_high_frag_p (gc_tuning_point tp,
31713171
#ifndef MULTIPLE_HEAPS
31723172
if (gen_number == max_generation)
31733173
{
3174-
float frag_ratio = (float)(dd_fragmentation (dynamic_data_of (max_generation))) / (float)generation_size (max_generation);
3174+
size_t maxgen_size = generation_size (max_generation);
3175+
float frag_ratio = (maxgen_size ? ((float)dd_fragmentation (dynamic_data_of (max_generation)) / (float)maxgen_size) : 0.0f);
31753176
if (frag_ratio > 0.65)
31763177
{
31773178
dprintf (GTC_LOG, ("g2 FR: %d%%", (int)(frag_ratio*100)));
@@ -3183,7 +3184,8 @@ gc_heap::dt_high_frag_p (gc_tuning_point tp,
31833184
ret = (fr > dd_fragmentation_limit(dd));
31843185
if (ret)
31853186
{
3186-
fragmentation_burden = (float)fr / generation_size (gen_number);
3187+
size_t gen_size = generation_size (gen_number);
3188+
fragmentation_burden = (gen_size ? ((float)fr / (float)gen_size) : 0.0f);
31873189
ret = (fragmentation_burden > dd_v_fragmentation_burden_limit (dd));
31883190
}
31893191
dprintf (GTC_LOG, ("h%d: gen%d, frag is %Id, alloc effi: %d%%, unusable frag is %Id, ratio is %d",

0 commit comments

Comments
 (0)