Do not use core::max_() with variable that can not be addressed

header struct is packed, and `core::max_()` takes the input as reference.
This commit is contained in:
Fatih Uzunoglu 2024-02-11 19:28:32 +02:00 committed by sfan5
parent 330150854b
commit 0dab737d60

@ -10,6 +10,7 @@
#include "CImage.h" #include "CImage.h"
#include "irrString.h" #include "irrString.h"
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
namespace irr namespace irr
{ {
@ -138,7 +139,8 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
if (header.ColorMapType) if (header.ColorMapType)
{ {
// Create 32 bit palette // Create 32 bit palette
const irr::u16 paletteSize = core::max_((u16)256, header.ColorMapLength); // ColorMapLength can lie, but so far we only use palette for 8-bit, so ensure it has 256 entries // `core::max_()` is not used here because it takes its inputs as references. Since `header` is packed, use the macro `MAX()` instead:
const irr::u16 paletteSize = MAX((u16)256u, header.ColorMapLength); // ColorMapLength can lie, but so far we only use palette for 8-bit, so ensure it has 256 entries
palette = new u32[paletteSize]; palette = new u32[paletteSize];
if( paletteSize > header.ColorMapLength ) if( paletteSize > header.ColorMapLength )