Skip to content
This repository
Browse code

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 authored May 10, 2013

Showing 1 changed file with 16 additions and 3 deletions. Show diff stats Hide diff stats

  1. 19  xbmc/guilib/GUITextLayout.cpp
19  xbmc/guilib/GUITextLayout.cpp
@@ -401,9 +401,22 @@ void CGUITextLayout::ParseText(const CStdStringW &text, uint32_t defaultStyle, v
401 401
     { // color
402 402
       size_t finish = text.Find(L']', pos + 5);
403 403
       if (on && finish != CStdString::npos && (size_t)text.Find(L"[/COLOR]",finish) != CStdString::npos)
404  
-      { // create new color
405  
-        newColor = colors.size();
406  
-        colors.push_back(g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5)));
  404
+      {
  405
+        color_t color = g_colorManager.GetColor(text.Mid(pos + 5, finish - pos - 5));
  406
+        vecColors::const_iterator it = std::find(colors.begin(), colors.end(), color);
  407
+        if (it == colors.end())
  408
+        { // create new color
  409
+          if (colors.size() <= 0xFF)
  410
+          {
  411
+            newColor = colors.size();
  412
+            colors.push_back(color);
  413
+          }
  414
+          else // we have only 8 bits for color index, fallback to first color if reach max.
  415
+            newColor = 0;
  416
+        }
  417
+        else
  418
+          // reuse existing color
  419
+          newColor = it - colors.begin();
407 420
         colorStack.push(newColor);
408 421
       }
409 422
       else if (!on && finish == pos + 5 && colorStack.size() > 1)

0 notes on commit 3950d3c

Please sign in to comment.
Something went wrong with that request. Please try again.