Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix color index overflow by reuse existed color in the vector. Fix #1…

…4293
  • Loading branch information...
commit 67fbfc5c5ed4f8186451a9f970c82a10b545d71c 1 parent 3a2bfc5
@ulion ulion authored
Showing with 16 additions and 3 deletions.
  1. +16 −3 xbmc/guilib/GUITextLayout.cpp
View
19 xbmc/guilib/GUITextLayout.cpp
@@ -401,9 +401,22 @@ void CGUITextLayout::ParseText(const CStdStringW &text, uint32_t defaultStyle, v
{ // color
size_t finish = text.Find(L']', pos + 5);
if (on && finish != CStdString::npos && (size_t)text.Find(L"[/COLOR]",finish) != CStdString::npos)
- { // create new color
- newColor = colors.size();
- colors.push_back(g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5)));
+ {
+ color_t color = 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);
}
else if (!on && finish == pos + 5 && colorStack.size() > 1)
Please sign in to comment.
Something went wrong with that request. Please try again.