Skip to content

Commit

Permalink
GUI: Fix for potential bad cursor palette access in warning case.
Browse files Browse the repository at this point in the history
Previously, if the colorsFound exceeded the maximum number of
cursor colors, a bad access to the cursor palette buffer could be
performed before the warning was emitted. This reordering avoids
that.
  • Loading branch information
klusark authored and digitall committed Nov 14, 2013
1 parent 180e660 commit 0ccc918
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gui/ThemeEngine.cpp
Expand Up @@ -1360,17 +1360,17 @@ bool ThemeEngine::createCursor(const Common::String &filename, int hotspotX, int

// If there is no entry yet for this color in the palette: Add one
if (!colorToIndex.contains(col)) {
if (colorsFound >= MAX_CURS_COLORS) {
warning("Cursor contains too many colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
return false;
}

const int index = colorsFound++;
colorToIndex[col] = index;

_cursorPal[index * 3 + 0] = r;
_cursorPal[index * 3 + 1] = g;
_cursorPal[index * 3 + 2] = b;

if (colorsFound > MAX_CURS_COLORS) {
warning("Cursor contains too many colors (%d, but only %d are allowed)", colorsFound, MAX_CURS_COLORS);
return false;
}
}

// Copy pixel from the 16 bit source surface to the 8bit target surface
Expand Down

0 comments on commit 0ccc918

Please sign in to comment.