From 8edd449a2329bea03373df335f5fa059744fe847 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 1 Aug 2024 16:00:16 +0800 Subject: [PATCH] Clamp graph meter values in "double" type A meter's "drawData.values[i] / total" quotient could overflow an integer type (the resulting value would be "unspecified"). Clamp the values in floating point type to prevent that. --- Meter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Meter.c b/Meter.c index 6d2d25a89..4463a90a0 100644 --- a/Meter.c +++ b/Meter.c @@ -259,8 +259,8 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { for (int col = 0; i < nValues - 1; i += 2, col++) { int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT; double total = MAXIMUM(this->total, 1); - int v1 = CLAMP((int) lround(data->values[i] / total * pix), 1, pix); - int v2 = CLAMP((int) lround(data->values[i + 1] / total * pix), 1, pix); + int v1 = (int) lround(CLAMP(data->values[i] / total * pix, 1.0, pix)); + int v2 = (int) lround(CLAMP(data->values[i + 1] / total * pix, 1.0, pix)); int colorIdx = GRAPH_1; for (int line = 0; line < GRAPH_HEIGHT; line++) {