From ff569b0d2e6f4cbc33e1a9109b7198745d85bd10 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 25 May 2014 18:11:14 +0200 Subject: CINE: Add a safeguard to avoid a divide by zero in Palette::save() --- engines/cine/pal.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/cine') diff --git a/engines/cine/pal.cpp b/engines/cine/pal.cpp index f3985c691e..18f260cab7 100644 --- a/engines/cine/pal.cpp +++ b/engines/cine/pal.cpp @@ -332,9 +332,9 @@ byte *Palette::save(byte *buf, const uint size, const Graphics::PixelFormat form // Save the palette to the output in the specified format for (uint i = firstIndex; i < firstIndex + numColors; i++) { - const uint r = (_colors[i].r * rNewMax) / rOrigMax; - const uint g = (_colors[i].g * gNewMax) / gOrigMax; - const uint b = (_colors[i].b * bNewMax) / bOrigMax; + const uint r = (_colors[i].r * rNewMax) / (rOrigMax == 0 ? 1 : rOrigMax); + const uint g = (_colors[i].g * gNewMax) / (gOrigMax == 0 ? 1 : gOrigMax); + const uint b = (_colors[i].b * bNewMax) / (bOrigMax == 0 ? 1 : bOrigMax); buf[i * format.bytesPerPixel + rBytePos] |= r << (format.rShift % 8); buf[i * format.bytesPerPixel + gBytePos] |= g << (format.gShift % 8); -- cgit v1.2.3