diff --git a/src/ZeDMD.cpp b/src/ZeDMD.cpp index 965175e..4741fff 100644 --- a/src/ZeDMD.cpp +++ b/src/ZeDMD.cpp @@ -201,7 +201,7 @@ bool ZeDMD::Open(int width, int height) void ZeDMD::SetPalette(uint8_t *pPalette) { - memcpy(&m_palette, pPalette, sizeof(m_palette)); + memcpy(&m_palette, pPalette, (sizeof(pPalette) < ZEDMD_MAX_PALETTE) ? sizeof(pPalette) : ZEDMD_MAX_PALETTE); } void ZeDMD::SetDefaultPalette(int bitDepth) diff --git a/src/ZeDMD.h b/src/ZeDMD.h index ecf4f37..8cd6e96 100644 --- a/src/ZeDMD.h +++ b/src/ZeDMD.h @@ -12,6 +12,7 @@ #define ZEDMD_MAX_WIDTH 256 #define ZEDMD_MAX_HEIGHT 64 +#define ZEDMD_MAX_PALETTE 64 * 3 #if defined(_WIN32) || defined(_WIN64) #define ZEDMDAPI __declspec(dllexport) @@ -103,7 +104,7 @@ class ZEDMDAPI ZeDMD uint8_t *m_pCommandBuffer; uint8_t *m_pPlanes; - uint8_t m_palette[64 * 3]; + uint8_t m_palette[ZEDMD_MAX_PALETTE] = {0}; uint8_t m_DmdDefaultPalette2Bit[12] = {0, 0, 0, 144, 34, 0, 192, 76, 0, 255, 127, 0}; uint8_t m_DmdDefaultPalette4Bit[48] = {0, 0, 0, 51, 25, 0, 64, 32, 0, 77, 38, 0, 89, 44, 0, 102, 51, 0, 115, 57, 0, 128, 64, 0,