Skip to content

Commit

Permalink
Merge pull request #2725 from ulion/fix_color_index_overflow
Browse files Browse the repository at this point in the history
Fix color index overflow by reuse existed color in the vector. Fix #14293
  • Loading branch information
ulion committed May 11, 2013
2 parents 8c8f790 + 67fbfc5 commit 3950d3c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions xbmc/guilib/GUITextLayout.cpp
Expand Up @@ -401,9 +401,22 @@ void CGUITextLayout::ParseText(const CStdStringW &text, uint32_t defaultStyle, v
{ // color { // color
size_t finish = text.Find(L']', pos + 5); size_t finish = text.Find(L']', pos + 5);
if (on && finish != CStdString::npos && (size_t)text.Find(L"[/COLOR]",finish) != CStdString::npos) if (on && finish != CStdString::npos && (size_t)text.Find(L"[/COLOR]",finish) != CStdString::npos)
{ // create new color {
newColor = colors.size(); color_t color = g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5));
colors.push_back(g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5))); vecColors::const_iterator it = std::find(colors.begin(), colors.end(), color);
if (it == colors.end())
{ // create new color
if (colors.size() <= 0xFF)
{
newColor = colors.size();
colors.push_back(color);
}
else // we have only 8 bits for color index, fallback to first color if reach max.
newColor = 0;
}
else
// reuse existing color
newColor = it - colors.begin();
colorStack.push(newColor); colorStack.push(newColor);
} }
else if (!on && finish == pos + 5 && colorStack.size() > 1) else if (!on && finish == pos + 5 && colorStack.size() > 1)
Expand Down

0 comments on commit 3950d3c

Please sign in to comment.