qt5base-lts/tests/auto/corelib
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
..
animation Extend tst_QPauseAnimation::pauseAndPropertyAnimations blacklist 2015-06-20 15:25:58 +00:00
codecs Fix utf8->utf16 BOM/ZWNBSP decoding. 2015-12-21 09:56:49 +00:00
global Fix compilation for WinRT 2015-12-14 08:43:15 +00:00
io tst_QTextStream::textModeOnEmptyRead(): Create file in temporary directory. 2016-03-11 11:26:14 +00:00
itemmodels tst_QItemModel: Use a QTemporaryDir for test data of QDirModel. 2015-11-27 22:50:26 +00:00
json Update testdata 2016-02-17 04:50:50 +00:00
kernel tst_QMetaType: fix misleading indention 2016-03-09 13:18:26 +00:00
mimetypes QMimeDatabase: follow symlinks when checking for FIFO etc. 2015-12-29 11:06:13 +00:00
plugin Disable tests requiring shared build when compiling statically 2016-03-11 08:30:27 +00:00
statemachine Merge remote-tracking branch 'origin/5.5' into 5.6 2016-01-19 10:03:01 +01:00
thread Fix signed integer overflows in tst_QAtomicInteger 2016-03-10 07:17:55 +00:00
tools QRect: fix UB (int overflow) in center() 2016-03-15 11:23:46 +00:00
xml Update copyright headers 2015-02-11 06:49:51 +00:00
corelib.pro iOS: Enable building of basic tests 2014-01-22 12:35:17 +01:00