From 00c427a20fff0505f4b99315cf300a37ff7c1c63 Mon Sep 17 00:00:00 2001 From: Boris Faure Date: Wed, 22 Apr 2020 23:52:58 +0200 Subject: [PATCH] termptyesc: avoid issue with integer promotion Found by UBSan: sgr-truecolors.sh... ../src/bin/termptyesc.c:737:35: runtime error: left shift of 244 by 24 places cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/bin/termptyesc.c:737:35 in --- src/bin/termptyesc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c index 3cb64ca3..957ce704 100644 --- a/src/bin/termptyesc.c +++ b/src/bin/termptyesc.c @@ -734,7 +734,10 @@ _approximate_truecolor_rgb(Termpty *ty, int r0, int g0, int b0) int c; int distance_min = INT_MAX; Evas_Object *textgrid; - const uint32_t color_msb = (r0 << 24) | (g0 << 16) | (b0 << 8); + const uint32_t color_msb = 0 + | (((uint8_t)r0) << 24) + | (((uint8_t)g0) << 16) + | (((uint8_t)b0) << 8); if (_tcc_find(color_msb, &chosen_color)) return chosen_color;