From 217c4d5d65882330ab67904e79915870ed25f966 Mon Sep 17 00:00:00 2001 From: kichikuou Date: Thu, 19 Sep 2024 07:32:30 +0900 Subject: [PATCH] Add guard against division by zero in vmDrawGauge.Draw() When `max` is 0, the gauge is drawn as empty. --- src/hll/vmDrawGauge.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hll/vmDrawGauge.c b/src/hll/vmDrawGauge.c index 2635ed6..766f3a0 100644 --- a/src/hll/vmDrawGauge.c +++ b/src/hll/vmDrawGauge.c @@ -103,8 +103,10 @@ static void vmDrawGauge_Draw(int handle, int now, int max) return; gfx_fill_with_alpha(&sf->texture, 0, 0, sf->texture.w, sf->texture.h, 255, 0, 255, 0); - int w = sf->texture.w * now / max; - gfx_copy_with_alpha_map(&sf->texture, 0, 0, &dg->tex, 0, 0, w, sf->texture.h); + if (max > 0) { + int w = sf->texture.w * now / max; + gfx_copy_with_alpha_map(&sf->texture, 0, 0, &dg->tex, 0, 0, w, sf->texture.h); + } } HLL_LIBRARY(vmDrawGauge,