If user specifies super large RGB values, it's possible for the
original code's idx to wrap around under minTermCOLOR24.

Signed-off-by: Fengguang Wu <[email protected]>
---
 src/command.C | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/command.C b/src/command.C
index 5369785..3fc3f1d 100644
--- a/src/command.C
+++ b/src/command.C
@@ -3348,20 +3348,15 @@ rxvt_term::process_osc_seq ()
 unsigned int
 rxvt_term::adapto_truecolor (unsigned int r, unsigned int g, unsigned int b)
 {
-  unsigned int idx_r = r / (255 / (Red_levels - 1));
-  unsigned int idx_g = g / (255 / (Green_levels - 1));
-  unsigned int idx_b = b / (255 / (Blue_levels - 1));
+  unsigned int idx_r = (r & 0xff) / (0xff / (Red_levels - 1));
+  unsigned int idx_g = (g & 0xff) / (0xff / (Green_levels - 1));
+  unsigned int idx_b = (b & 0xff) / (0xff / (Blue_levels - 1));
   unsigned int idx;
 
   idx = minTermCOLOR24 + idx_r * Blue_levels * Green_levels +
                          idx_g * Blue_levels +
                          idx_b;
 
-  if (idx > maxTermCOLOR24) {
-    rxvt_warn ("24-bit RGB overflow: %x %x %x\n", r, g, b);
-    idx = maxTermCOLOR24;
-  }
-
   pix_colors_focused [idx].free (this);
   pix_colors_focused [idx].set (this, rgba (r * 0x0101,
                                             g * 0x0101,
-- 
2.8.1


_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/rxvt-unicode

Reply via email to