From 803fe613d28513f07ad2be0379b23e046df7651f Mon Sep 17 00:00:00 2001 From: Lactozilla <jp6781615@gmail.com> Date: Tue, 21 Nov 2023 16:25:55 -0300 Subject: [PATCH] Fix possible overflow in PaletteRemap_AddDesaturation --- src/r_translation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/r_translation.c b/src/r_translation.c index 99e50a218..24019ed00 100644 --- a/src/r_translation.c +++ b/src/r_translation.c @@ -302,9 +302,9 @@ boolean PaletteRemap_AddDesaturation(remaptable_t *tr, int start, int end, doubl double intensity = (pMasterPalette[c].s.red * 77 + pMasterPalette[c].s.green * 143 + pMasterPalette[c].s.blue * 37) / 255.0; tr->remap[c] = NearestColor( - min(255, (int)(r1 + intensity*r2)), - min(255, (int)(g1 + intensity*g2)), - min(255, (int)(b1 + intensity*b2)) + min(255, max(0, (int)(r1 + intensity*r2))), + min(255, max(0, (int)(g1 + intensity*g2))), + min(255, max(0, (int)(b1 + intensity*b2))) ); }