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.
This commit is contained in:
Tomay
2021-06-11 00:23:46 +02:00
committed by Vadim Zeitlin
parent 527bcb246b
commit b52f00492e
4 changed files with 8 additions and 5 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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] ;

View File

@@ -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();