tga: memset the whole palette array, not only the palette_size

This commit is contained in:
Albert Astals Cid 2019-05-01 01:44:47 +02:00
parent 0db5c89c5f
commit bcce48012e

View File

@ -201,16 +201,17 @@ static bool LoadTGA(QDataStream &s, const TgaHeader &tga, QImage &img)
} }
// Read palette. // Read palette.
char palette[768]; static const int max_palette_size = 768;
char palette[max_palette_size];
if (info.pal) { if (info.pal) {
// @todo Support palettes in other formats! // @todo Support palettes in other formats!
const int size = 3 * tga.colormap_length; const int palette_size = 3 * tga.colormap_length;
const int dataRead = s.readRawData(palette, size); const int dataRead = s.readRawData(palette, palette_size);
if (dataRead < 0) { if (dataRead < 0) {
return false; return false;
} }
if (dataRead < size) { if (dataRead < max_palette_size) {
memset(&palette[dataRead], 0, size - dataRead); memset(&palette[dataRead], 0, max_palette_size - dataRead);
} }
} }