Go to file
Marc Mutz e4c6d73f92 QRect: fix UB (int overflow) in center()
QRect::center() should be defined for any
  QRect(x1,y1,x2,x2), INT_MIN <= x1, x2, y1, y2 <= INT_MAX
because the average of two signed integers is always
representable as a signed integer.

But not when it's calculated as (x1+x2)/2, since that
expression overflows when x1 > INT_MAX - x2.

Instead of playing games with Hacker's Delight-style
expressions, or use Google's patented algorithm, which
requires two divisions, take advantage of the fact that
int is not intmax_t and perform the calculation in the
qint64 domain. The cast back to int is always well-
defined since, as mentioned, the result is always
representable in an int.

Fix a test-case that expected a nonsensical result due
to overflow.

[ChangeLog][QtCore][QRect] Fixed integer overflow in
center(). This fixes the result for some corner-cases
like a 1x1 rectangle at (INT_MIN, INT_MIN), for which
the previous implementation could return anything
(due to invoking undefined behavior), but commonly
returned (0, 0).

Change-Id: I1a885ca6dff770327dd31655c3eb473fcfeb8878
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-03-15 11:23:46 +00:00
bin syncqt.pl: say "ERROR" when it's an error 2015-12-08 06:32:24 +00:00
config.tests alsatest: Fix the check to treat alsalib 1.1.x as correct version 2016-03-07 14:37:29 +00:00
dist Update the Qt 5.5.1 changelog for qtbase 2015-09-23 06:49:28 +00:00
doc Remove WebEngine examples metadata 2016-03-07 14:24:57 +00:00
examples Skip spurious .toLower() on returns of QUrl::scheme() 2016-03-10 15:00:59 +00:00
lib
mkspecs Disable c++ standard compiler flags for the host build 2016-03-08 19:30:04 +00:00
qmake qmake: fix UB in QMakeParser::putHashStr() 2016-03-10 12:30:46 +00:00
src QRect: fix UB (int overflow) in center() 2016-03-15 11:23:46 +00:00
tests QRect: fix UB (int overflow) in center() 2016-03-15 11:23:46 +00:00
tools Allow overriding Android NDK host on Windows 2016-03-10 11:57:39 +00:00
util Don't use QStringLiteral in comparisons 2016-01-28 18:00:47 +00:00
.gitattributes Update the git-archive export options 2012-09-07 15:39:31 +02:00
.gitignore rewrite qtAddToolEnv() 2016-01-08 09:36:13 +00:00
.qmake.conf Bump version 2016-02-18 07:38:22 +00:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
configure Merge remote-tracking branch 'origin/5.6.0' into 5.6 2016-02-15 08:09:50 +01:00
configure.bat Move the official Qt version from qglobal.h to .qmake.conf 2015-10-14 20:12:57 +00:00
header.BSD Updated BSD licensed file headers 2015-02-15 07:41:17 +00:00
header.COMM Add header template for commercial only modules 2015-10-19 10:37:18 +00:00
header.FDL Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL3 Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL3-COMM Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL21 Update copyright headers 2015-02-11 06:49:51 +00:00
header.LGPL-ONLY Update copyright headers 2015-02-11 06:49:51 +00:00
INSTALL Doc: Update links in INSTALL file 2015-02-16 09:06:41 +00:00
LGPL_EXCEPTION.txt Update copyright headers 2015-02-11 06:49:51 +00:00
LICENSE.FDL
LICENSE.GPLv3 fix up license references 2015-08-13 11:13:09 +00:00
LICENSE.LGPLv3 Bump copyright year to 2016 2016-01-29 13:30:04 +00:00
LICENSE.LGPLv21 Bump copyright year to 2016 2016-01-29 13:30:04 +00:00
LICENSE.PREVIEW.COMMERCIAL Update copyright headers 2015-02-11 06:49:51 +00:00
qtbase.pro Install fixqt4headers.pl script 2015-11-14 12:46:50 +00:00
sync.profile make a proper header-only module for QtZlib 2015-11-17 20:22:17 +00:00