Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2725 from ulion/fix_color_index_overflow

Fix color index overflow by reuse existed color in the vector. Fix #14293
  • Loading branch information...
commit 3950d3c6181d1afba2a67e01ac7bf1d22880ffbb 2 parents 8c8f790 + 67fbfc5
@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.