From b52f00492e4c6ff199488e1997fff19a8e158bb7 Mon Sep 17 00:00:00 2001 From: Tomay Date: Fri, 11 Jun 2021 00:23:46 +0200 Subject: [PATCH] Fix checks for wxPalette index validity Consistently check that the index is valid in all ports, instead of using hard-coded 255 rather than the actual number of colours in some of them and forgetting to check that the index is positive in others. Closes #19198. --- src/generic/paletteg.cpp | 7 +++++-- src/msw/palette.cpp | 2 +- src/osx/palette.cpp | 2 +- src/x11/palette.cpp | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/generic/paletteg.cpp b/src/generic/paletteg.cpp index af3fe56e93..6b3530e864 100644 --- a/src/generic/paletteg.cpp +++ b/src/generic/paletteg.cpp @@ -131,8 +131,11 @@ bool wxPalette::GetRGB(int pixel, unsigned char *green, unsigned char *blue) const { - if (!m_refData) return false; - if (pixel >= M_PALETTEDATA->m_count) return false; + if ( !m_refData ) + return false; + + if ( pixel < 0 || pixel >= M_PALETTEDATA->m_count ) + return false; wxPaletteEntry& p = M_PALETTEDATA->m_entries[pixel]; if (red) *red = p.red; diff --git a/src/msw/palette.cpp b/src/msw/palette.cpp index 6d430f9b7a..e4584a5bb5 100644 --- a/src/msw/palette.cpp +++ b/src/msw/palette.cpp @@ -156,7 +156,7 @@ bool wxPalette::GetRGB(int index, if ( !m_refData ) return false; - if (index < 0 || index > 255) + if ( index < 0 || index >= GetColoursCount() ) return false; PALETTEENTRY entry; diff --git a/src/osx/palette.cpp b/src/osx/palette.cpp index e0519daa13..0d388946a3 100644 --- a/src/osx/palette.cpp +++ b/src/osx/palette.cpp @@ -122,7 +122,7 @@ bool wxPalette::GetRGB(int index, unsigned char *red, unsigned char *green, unsi if ( !m_refData ) return false; - if (index < 0 || index >= M_PALETTEDATA->m_count) + if ( index < 0 || index >= M_PALETTEDATA->m_count ) return false; const wxColour& col = M_PALETTEDATA->m_palette[index] ; diff --git a/src/x11/palette.cpp b/src/x11/palette.cpp index 1cdf8bc4ad..1559ecac17 100644 --- a/src/x11/palette.cpp +++ b/src/x11/palette.cpp @@ -242,7 +242,7 @@ bool wxPalette::GetRGB(int index, if ( !m_refData ) return false; - if (index < 0 || index > 255) + if ( index < 0 || index >= GetColoursCount() ) return false; wxList::compatibility_iterator node = M_PALETTEDATA->m_palettes.GetFirst();