From 837b5d458970f3981859cb9dfa0cec5fcd6d0c4f Mon Sep 17 00:00:00 2001 From: Tilo Nitzsche Date: Mon, 23 Nov 2015 19:28:25 +0100 Subject: [PATCH] Fix undefined behavior in qRgba(). Shifting a signed integer that overflows is undefined behavior. All masks were changed to unsigned in qRgb and qRgba. While the alpha value is enough to fix the undefined behavior, Visual C++ generates slow code if not all of those constants are unsigned. Change-Id: Ia0ec3e9464088495173b4ad9c2e37a49e6f8e987 Task-number: QTBUG-49595 Reviewed-by: Thiago Macieira --- src/gui/painting/qrgb.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qrgb.h b/src/gui/painting/qrgb.h index f7f2185bef..ca9fc03d14 100644 --- a/src/gui/painting/qrgb.h +++ b/src/gui/painting/qrgb.h @@ -58,10 +58,10 @@ inline Q_DECL_CONSTEXPR int qAlpha(QRgb rgb) // get alpha part of { return rgb >> 24; } inline Q_DECL_CONSTEXPR QRgb qRgb(int r, int g, int b)// set RGB value -{ return (0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } +{ return (0xffu << 24) | ((r & 0xffu) << 16) | ((g & 0xffu) << 8) | (b & 0xffu); } inline Q_DECL_CONSTEXPR QRgb qRgba(int r, int g, int b, int a)// set RGBA value -{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } +{ return ((a & 0xffu) << 24) | ((r & 0xffu) << 16) | ((g & 0xffu) << 8) | (b & 0xffu); } inline Q_DECL_CONSTEXPR int qGray(int r, int g, int b)// convert R,G,B to gray 0..255 { return (r*11+g*16+b*5)/32; }