From 0dab737d602a77e98acb159ddd6bb2ac89f36cff Mon Sep 17 00:00:00 2001 From: Fatih Uzunoglu Date: Sun, 11 Feb 2024 19:28:32 +0200 Subject: [PATCH] Do not use `core::max_()` with variable that can not be addressed header struct is packed, and `core::max_()` takes the input as reference. --- source/Irrlicht/CImageLoaderTGA.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/Irrlicht/CImageLoaderTGA.cpp b/source/Irrlicht/CImageLoaderTGA.cpp index bc8298f..9324f3d 100644 --- a/source/Irrlicht/CImageLoaderTGA.cpp +++ b/source/Irrlicht/CImageLoaderTGA.cpp @@ -10,6 +10,7 @@ #include "CImage.h" #include "irrString.h" +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) namespace irr { @@ -138,7 +139,8 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const if (header.ColorMapType) { // 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]; if( paletteSize > header.ColorMapLength )