Commit Graph

26653 Commits

Author SHA1 Message Date
Marc Mutz
9739cae4c8 QRawFont: fix UB (misaligned load) in fontTable()
Found by UBSan:

  qrawfont.cpp:618:60: runtime error: load of misaligned address 0x2acee92a5569 for type 'const quint32', which requires 4 byte alignment

Fix by using MAKE_TAG(), like everywhere else, instead
of a load through a type-punned and misaligned pointer.

Change-Id: I52b88ca05a57f7d8c5e5bce953384de49514079b
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-03-15 10:39:24 +00:00
Marc Mutz
add95c5510 tst_QSqlQuery: fix UBs (invalid downcasts, member calls)
The existing code derived a helper class from QSqlResult and
overloaded two protected functions as public ones so the test
could call them after casting QSqlResults to that helper class.

Both the cast (which is a C-style cast, but with combined
static_cast and const_cast semanics) and the following member
function call are undefined behavior.

Fix by making the test class a friend of QSqlResult, and
dropping the casts.

Change-Id: I09de2e2b46976d01cfce25892aec6ad36881d3eb
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
2016-03-15 10:39:20 +00:00
Marc Mutz
52a599bb56 QCosmeticStroker: fix several UBs involving << with a negative LHS
Left-shifts of negative values are undefined in C++. In particular,
they don't behave arithmetically.

Reported by UBSan:

  qcosmeticstroker.cpp: 72:15: runtime error: left shift of negative value -14/-19/-32/-33/-34/-37/-38/-63/-64/-192/-384/-1280
  qcosmeticstroker.cpp:444:20: runtime error: left shift of negative value -64
  qcosmeticstroker.cpp:451:26: runtime error: left shift of negative value -1
  qcosmeticstroker.cpp:483:26: runtime error: left shift of negative value -1
  qcosmeticstroker.cpp:762:20: runtime error: left shift of negative value -64
  qcosmeticstroker.cpp:774:26: runtime error: left shift of negative value -1
  qcosmeticstroker.cpp:813:47: runtime error: left shift of negative value -1
  qcosmeticstroker.cpp:839:20: runtime error: left shift of negative value -64
  qcosmeticstroker.cpp:851:26: runtime error: left shift of negative value -1
  qcosmeticstroker.cpp:889:47: runtime error: left shift of negative value -1
  qcosmeticstroker.cpp:932:27: runtime error: left shift of negative value -64
  qcosmeticstroker.cpp:995:27: runtime error: left shift of negative value -3/-64

Fix by using ordinary multiplication instead, because negative
left-hand-side values don't look like they are an error.

Change-Id: Icbebd41f6ddd3dca4abd385585fc0f82064fe8b6
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
2016-03-15 10:39:16 +00:00
Milla Pohjanheimo
1a9e1fbbfc Remove restoreDockWidget from BLACKLIST
Tested on the Ubuntu 14.04 VM. The test didn't fail anymore with
2000 test rounds

Change-Id: Ic12c60e5ebf9c234358a6983bf87fa0a88d7886e
Reviewed-by: Tony Sarajärvi <tony.sarajarvi@theqtcompany.com>
2016-03-15 09:41:09 +00:00
Błażej Szczygieł
11836be127 Remove Qt::WA_OutsideWSRange flag even if the widget is not yet visible.
Show the widget when its initial size is 0 and the layout changes the
size during showing.

Task-number: QTBUG-51788
Change-Id: I3251ac27328f9715ff13d96e1b82fbf824d9e79d
Reviewed-by: Dmitry Shachnev <mitya57@gmail.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
2016-03-15 09:16:27 +00:00
Morten Johan Sørvig
c4886ca427 Cocoa: Fix crash on screen disconnect.
Maintain virtual siblings list on screen deletion.

QCocoaIntegration::updateScreens() has a loop which
will delete all non-current QScreen objects using
QPlatformIntegration::destroyScreen().

destroyScreen() vill eventually call QWindowPrivate::
setTopLevelScreen() which accesses the virtual siblings
list for the deleted screen.

This can cause a stale pointer access if the virtual
screen list is not up to date, especially when disconnecting
two screens at the same time.

Change-Id: Ia6b9d01edf8e5eea25b64604a2b3b28b173125f7
Task-number: QTBUG-48275
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
2016-03-15 04:25:50 +00:00
Antonio Larrosa
063ad1c8b6 Don't include by default ciphers that are not supported
There could be cases (mostly when compiled on old systems, since modern
openssl versions don't include such insecure ciphers) in which
defaultCiphers included a cipher that wasn't in the supported ciphers
list. With this patch we make sure that defaultCiphers is a subset of
supportedCiphers

Change-Id: I545ea21f5fd3a6ed13b366cdd56a1393233f9fc9
Reviewed-by: Richard J. Moore <rich@kde.org>
2016-03-14 00:00:43 +00:00
Richard J. Moore
5fe0e41e79 Do not send the trailing dot of a hostname as part of the SNI
The SNI extension must not include the trailing dot, even though this
is legitimate for the host header.

Task-number: QTBUG-51821
Change-Id: Ib7a7d8b1f8f98bc99ae745b03d2b97e507adefaf
Reviewed-by: Daniel Molkentin (ownCloud) <danimo@owncloud.com>
2016-03-13 00:05:38 +00:00
Marc Mutz
978804d2c2 QNetworkHeaders: fix UB (invalid enum value) in Private::parseAndSetHeader()
Found by UBSan:

  qnetworkrequest.cpp:1016:19: runtime error: load of value 4294967295, which is not a valid value for type 'KnownHeaders'

KnownHeaders does not contain a failure state, and no negative
values. -1 is therefore not a valid value for an object of type
KnownHeaders, so loading one is considered UB.

Fix by returning the result of parseHeaderName() as an int,
only casting to KnownHeaders after checking for the failure
case.

Change-Id: I6b165fe2b15c747344a9b2750bb753582c5bcbeb
Reviewed-by: Richard J. Moore <rich@kde.org>
2016-03-12 19:04:14 +00:00
Friedemann Kleint
514c202da9 Add a manual test for foreign windows.
Add a command line tool that can either take a list of window ids and output
information on them using a verbose debug stream or embed foreign
windows using QWidget::createWindowContainer().

Task-number: QTBUG-41186
Change-Id: I14e436b5d08828f5b78b29e0701daeffe11367d3
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
2016-03-11 16:03:34 +00:00
Friedemann Kleint
a8c72b7671 tst_QTextStream::textModeOnEmptyRead(): Create file in temporary directory.
A test should not write to its directory. Amends change
d0b54cede8.

Task-number: QTBUG-47176
Change-Id: If15258b4aed199792fab422b7ac1d74e22a9e322
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
2016-03-11 11:26:14 +00:00
Morten Johan Sørvig
a2d58025b6 Cocoa: Improve native view lifetime accuracy.
Ideally all native NSWindows and NSViews owned by
QCocoaWindow should be deallocated during the QCocoaWindow
destructor. In reality this does not always happen
since Cocoa is free to hold references to the views
after Qt releases its reference.

We can help Cocoa clean up:

- Clear the first responder for the NSWindow under
  the ~QCocoaWndow() autoreleasepool.

- Use an autoreleasepool to clean up temp objects
  from [NSWindow orderFront:] immediately.

Together this makes the QNSView lifetime be contained
by the QCocoaWindow lifetime, at least for simple
QWindow usage. It also fixes the observed memory leak
reported in QTBUG-51766

Change-Id: Idd224f54ebd6f61f274461a204ff30c666b22768
Task-number: QTBUG-51766
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-11 11:00:14 +00:00
Maurice Kalinowski
1929e48bba winrt: Fix painting glitches when orientation changes
In addition to handling the pure rotation enforce a size change as well.
This way content is redrawn for the correct orientation.
It was done for Windows Phone 8.1 already, we only need to extent this
to Windows 10.

Task-number: QTBUG-50336
Change-Id: I6b3b964f44b631757ea856331c50f53c39ed9ec3
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
2016-03-11 09:38:55 +00:00
Maurice Kalinowski
0c51277bb8 winrt: add logging to QWinRTScreen
Task-number: QTBUG-38114
Change-Id: Id653487a03ca2920c46cf16e45f28677a69fa570
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
2016-03-11 09:38:51 +00:00
Maurice Kalinowski
71a36d0b65 Disable tests requiring shared build when compiling statically
Change-Id: I06ec53e46d2f61f1685899b0f8a4d385051095d6
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
2016-03-11 08:30:27 +00:00
Samuel Gaist
cf827f2167 Ported Qt 4 fix when getting an invalid native key on Windows
Task-number: QTBUG-36061
Change-Id: Ibde65735d861af4e1ef768e9e4314d30fed534a1
Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
2016-03-10 22:20:35 +00:00
Joerg Bornemann
ac8dae8b5e QLocalServer/Win: Fix race condition in listen().
Suppose a client connects while the QLocalServer is still in the loop
that calls addListener. The connection would SetEvent(eventHandle),
but every call to ConnectNamedPipe would ResetEvent(eventHandle).
Thus, the connection is never detected by the notifier on eventHandle.
  Callers of addListener must check the connection state of every
listener to make sure that no client connected while setting up
listeners.

Task-number: QTBUG-49254
Change-Id: Ia961927ea76973708e6e3f73510695eb5d6a0e4c
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-03-10 17:32:49 +00:00
Allan Sandfeld Jensen
8589bb334f Enable most of tst_qstatictext on non-developer builds
Only two tests inside tst_qstatictext required private symbols, so
we can enable the rest on all builds.

Change-Id: Id222ba01d9676c40b6447c1526ee127fcc2090d3
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-03-10 15:45:41 +00:00
Joerg Bornemann
39efe3c84d Fix glitch in tst_QLocalSocket::sendData
In one code path the test checked for the emission of a readyRead()
signal without waiting for it.
This code path was never hit, neither on Windows nor on Unix platforms.

Change-Id: Ifbe464400a2a1ba8eab49bd60315289040e6bbde
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-03-10 15:03:37 +00:00
Edward Welbourne
65f88f3a5d Deduplicate a condition to make clear that several cases ask it.
QNetworkAccessManager::createRequest() had three checks relevant only
to GET and HEAD requests; rather than testing for this in each of the
cases, test for it once and skip all three if it fails.  Tidied up the
residue of conditionals in the process.

Change-Id: I7baee8067a03afdc7cb0a77f1a50759dc4233843
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-10 15:01:09 +00:00
Edward Welbourne
6a2892bdef Skip spurious .toLower() on returns of QUrl::scheme()
QUrl::setScheme() parses and canonicalises the scheme, so that
scheme() always returns a lower-case string anyway; no need to
.toLower() it.

Change-Id: Ied00814b63f159386a42552dcf06346ee56f9f97
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-10 15:00:59 +00:00
Olivier Goffart
c9210d392c Add argument names to the function signatures in headers
Sometimes, in the .cpp, the declaration has the argument name in comments
because it is not used (instead of using Q_UNUSED). The old qdoc could
parse that, but once clang is used, these comments are not seen anymore.

So add the argument names to the headers. This is also good for things
like auto completion, which uses only the header to know what the
argument name is.

I grepped for " */)" and made sure all the functions that are documented
have the right arguments. I also added the name to all the function around
for consistency.

Change-Id: I1aaa37e25a1985f7f51653f047a1ac2633242b56
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Martin Smith <martin.smith@theqtcompany.com>
2016-03-10 13:30:04 +00:00
Friedemann Kleint
45dc347a95 tst_QStaticText: Output verbose message for test failures.
Factor out function to check on the pixel color that
outputs a verbose message on failure.

Change-Id: I2331fe45f35327d1ff8ae547a58d93a2e6fe9184
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-03-10 12:37:47 +00:00
Marc Mutz
1fd0d57ce3 qmake: fix UB in QMakeParser::putHashStr()
Found by UBSan:

  qmake/library/qmakeparser.cpp:278:33: runtime error: null pointer passed as argument 2, which is declared to never be null

Guard the call.

Change-Id: I99341ab439a511f366dae9344ddcc8727c33b9b6
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-03-10 12:30:46 +00:00
Oswald Buddenhagen
f3487308e4 fix file separators in target.targets INSTALLS
Task-number: QTBUG-51775
Change-Id: I8d9442bfd5084f1670b79dfdd422638bc62780aa
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
2016-03-10 12:21:57 +00:00
Allan Sandfeld Jensen
5655d061b2 Xft antialias settings must not override requested NoAntialias
If Xft enabled font antialiasing, QFont::NoAntialias would have no
effect as it would be overridden.

Change-Id: I4dae264bc6674ae81f181cc9ce85851174d42544
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
2016-03-10 12:11:26 +00:00
Eskil Abrahamsen Blomfeldt
437f5662d3 Allow overriding Android NDK host on Windows
The -android-ndk-host argument to configure existed in the shell
script, but not in the Windows version. When using a 64-bit NDK
but a 32-bit host compiler (which is what we bundle with our
SDK), we would not detect the correct NDK host, making it impossible
to build Qt with this combo.

[ChangeLog][Android] Added -android-ndk-host configure option on
Windows.

Change-Id: Ie6a92b66e6875ed53f46fe41ecced70c3ec67585
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-03-10 11:57:39 +00:00
Marc Mutz
fb196e8807 QMimeMagicRule: fix UB (misaligned load) in matchNumber<T>()
Found by UBSan:

  qmimemagicrule.cpp:166:53: runtime error: load of misaligned address 0x00000124bcb9 for type 'const short unsigned int', which requires 2 byte alignment
  qmimemagicrule.cpp:166:53: runtime error: load of misaligned address 0x00000124bcb9 for type 'const unsigned int', which requires 4 byte alignment

Fix by using new qUnalignedLoad<T>() instead of a
load through a type-punned pointer and misaligned
pointer.

Change-Id: I6b876f1ce7e01369fbb25a51263d1ad04be07d52
Reviewed-by: David Faure <david.faure@kdab.com>
2016-03-10 10:57:53 +00:00
Friedemann Kleint
62e0a98282 Fix debug operators for QPageSize/QPageLayout.
Remove placeholder formatting and add noquote.

Change-Id: I4a89f88778caf007ce42bbf57edfb514fe76bcdb
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
2016-03-10 10:53:51 +00:00
Marc Mutz
807240a883 QJsonParser: fix UB (misaligned store) in Parser::parseNumber()
Found by UBSan:

  qjsonparser.cpp:741:30: runtime error: store to misaligned address 0x0000019b1e94 for type 'quint64', which requires 8 byte alignment

Fix by using the qToLittleEndian() overload that can
store to misaligned memory.

Change-Id: Ib84bd30b13c68f7fdb8870c9fbbfac15cff0112d
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
2016-03-10 09:45:34 +00:00
Marc Mutz
f647375275 Fix signed integer overflows in tst_QAtomicInteger
Signed integer overflows and underflows are undefined
behavior. A test that invokes UB tests nothing, because
the standard permits any outcome.

Fix by guarding the respective operations so
they are not executed if they would overflow
or underflow.

Change-Id: I40354ee88f40e4b47b70eac7790dc3a79ac70a57
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
2016-03-10 07:17:55 +00:00
Gabriel de Dietrich
85a57f7a2e Wheel event widget: Harden logic an extra bit
This is quite an unlikely scenario, but not impossible.

It could be that the wheel widget is destroyed during
an update phase event. In that case, wheel_widget would
be a dangling pointer for any subsequent wheel event.
We protect against this with a QPointer.

However, that would mean that if the next wheel event
were to be an end phase event, that event would be lost.
So we go through the usual code path, except that we won't
set wheel_widget in the case of an end phase event.

Change-Id: I59a912b845dcc249e1edc60b4dc28bf308d807d9
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
2016-03-09 23:46:50 +00:00
Marc Mutz
2020d2cb63 QObject: fix GCC 6 warning about qt_static_metacall's 'hidden' attribute use
This warning is triggered when we try to apply the Q_DECL_HIDDEN
attribute to a class in an unnamed namespace. Such classes are
already not exported.

  qobjectdefs.h:175:108: warning: ‘visibility’ attribute ignored [-Wattributes]
  qobjectdefs.h:198:108: warning: ‘visibility’ attribute ignored [-Wattributes]

Added a test on gadgets (and QObjects) in unnamed namespaces,
because qtbase currently does not contain such Q_GADGETs.

Done-with: Thiago Macieira <thiago.macieira@intel.com>
Change-Id: Ic747cc2ab45e4dc6bb70ffff1438c747b05c5672
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
2016-03-09 20:11:28 +00:00
Dyami Caliri
f8f1bac3f0 Accept LFCRLF to mark end of HTTP Headers
Some embedded servers use LF to mark the end of an individual header,
but use CRLF to mark the end of all the headers. The GoPro WiFi
interface does this, as an example.

Change-Id: I227ab73622c84f439a6cf8703d020393c4d8bf69
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Markus Goetz (Woboq GmbH) <markus@woboq.com>
2016-03-09 15:47:18 +00:00
Shawn Rutledge
d7db6c6c19 xcb: mark mouse events from tablet devices as synthesized
Task-number: QTBUG-51617
Change-Id: Ic1d258c56165947ff821b1bf4d044bcf29b41a3b
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
2016-03-09 14:42:30 +00:00
Friedemann Kleint
d29443c9c8 Manual touch test: Remove QDebug operator for QTouchDevice.
It now exists in QtGui.

Task-number: QTBUG-48849
Change-Id: I9107c96e0010252bc50bcb02ef006cb46bd942df
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
2016-03-09 14:26:04 +00:00
Jarek Kobus
cb24903ef4 Generate QVariant::fromValue(enum_value) for enum values
Instead of just QVariant(enum_value).

Task-number: QTBUG-49383
Change-Id: Id57c65b68d4328816046bc35301dc6afba47b727
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
2016-03-09 13:51:39 +00:00
Friedemann Kleint
7d374b7ba6 QString::vasprintf(): Use quintptr when casting pointer for %p.
Previously, the macro Q_OS_WIN64 was checked, causing warnings:

tools\qstring.cpp(6183): warning C4311: 'reinterpret_cast': pointer truncation from 'void *' to 'unsigned long'
tools\qstring.cpp(6183): warning C4302: 'reinterpret_cast': truncation from 'void *' to 'unsigned long'

when compiling WinRT/64bit, where it is not defined.

Change-Id: Ib9d8405108c85170aba18b13f9c64083136bc5ee
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@theqtcompany.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
2016-03-09 13:45:26 +00:00
Marc Mutz
62e89f4745 tst_QMetaType: fix misleading indention
As found by GCC 6:

  tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp:1476:9: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
         tn += ">";
         ^~
  tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp:1474:5: note: ...this ‘if’ clause, but it is not
     if (tn.endsWith('>'))
     ^~

Fix += argument from char[2] to char as a drive-by.

Change-Id: I814dc58830934cac7fcf81eb7fd7564b2abeb631
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
2016-03-09 13:18:26 +00:00
Marc Mutz
3856099d9a QGestureManager: fix UB in filterEvent()
The code infers from the presence of an address in a
QHash<QGesture *, ...> that the address belongs to a
QGesture. So far that is fine enough.

But in order to perform the lookup, it static_cast<>s
the QObject* argument to a QGesture* for the QHash::
contains() call. Even though the pointer is not
dereferenced, the cast is UB. Says UBSan:

  qgesturemanager.cpp:558:73: runtime error: downcast of address 0x2ab83364f3a0 which does not point to an object of type 'QGesture'
  0x2ab83364f3a0: note: object is of type 'QDBusConnectionManager'

which is a particularly hideous error message because
of the constantly-changing completely-unrelated actual
type in the second line of the message:

     52 QDBusConnectionManager
     19 QSocketNotifier
     14 QFusionStyle
     13 QAction
      6 QApplication
      3 QGraphicsWidget
      1 Window
      1 TestRunnable
      1 RectWidget
      1 QTimer
      1 QSingleShotTimer
      1 QOffscreenSurface
      1 QGraphicsProxyWidget
      1 QDefaultAnimationDriver
      1 QDBusPendingCallWatcherHelper

This error is also _very_ common, triggered 116 times
in a single run of make -C tests/auto check.

Fix by using qobject_cast first and then doing the
lookup only when the cast succeeded.

Depending on the performance of qobject_cast<>, this
may actually perform better, too.

Change-Id: I884ec7d885711acc3c1d004ce93c628268d8fc18
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
2016-03-09 13:18:19 +00:00
Marc Mutz
1bfc7f680f QString, QJson, QHash: Fix UBs involving unaligned loads
Found by UBSan:

  src/corelib/tools/qstring.cpp:587:42: runtime error: load of misaligned address 0x2acbf4b7551b for type 'const long long int', which requires 8 byte alignment
  src/corelib/json/qjson_p.h:405:30: runtime error: store to misaligned address 0x0000019b1e52 for type 'quint64', which requires 8 byte alignment
  src/corelib/tools/qhash.cpp:116:27: runtime error: load of misaligned address 0x2b8f9ce80e85 for type 'const qlonglong', which requires 8 byte alignment
  src/corelib/tools/qhash.cpp:133:26: runtime error: load of misaligned address 0x2b8f9ce80e8d for type 'const ushort', which requires 2 byte alignment

Fix by memcpy()ing into a local variable. Wrap this trick in
template functions in qsimd_p.h. These are marked as always-
inline and use __builtin_memcpy() where available in an
attempt to avoid the memcpy() function call overhead in debug
builds.

While this looks prohibitively expensive, from the pov of the
C++ abstract machine, it is 100% equivalent, except for the
absence of undefined behavior. In one case, the cast produces
a local temporary which is then copied into the function, and
in the other case, that local variable comes from return value
of qUnalignedLoad().

Consequently, GCC compiles these two versions into identical
assembler code (only verfied for ucstrncmp, but there's no
reason to believe that it wouldn't hold for the other cases,
too).

Task-number: QTBUG-51651
Change-Id: Ia50d4a1d7580b6f803e0895c9f3d89c7da37840c
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
2016-03-09 13:16:19 +00:00
Marc Mutz
1b441c3941 Q*Application: fix UB caused by accessing QGuiApplication from QCoreApplication ctor
As reported by ubsan:

  src/gui/kernel/qplatformintegration.cpp:463:10: runtime error: downcast of address 0x7ffdc2942490 which does not point to an object of type 'QGuiApplication'
  0x7ffdc2942490: note: object is of type 'QCoreApplication'

  src/gui/kernel/qplatformintegration.cpp:466:14: runtime error: downcast of address 0x7ffdc2942490 which does not point to an object of type 'QGuiApplication'
  0x7ffdc2942490: note: object is of type 'QCoreApplication'

  src/gui/kernel/qplatformintegration.cpp:466:43: runtime error: member call on address 0x7ffdc2942490 which does not point to an object of type 'QGuiApplication'
  0x7ffdc2942490: note: object is of type 'QCoreApplication'

to name just a few which are reported when running gui and widget
auto-tests; there're definitely more where these came from.

This is caused by QCoreApplication::init() being called from the
QCoreApplication ctor, calling virtual functions on Q*AppPrivate,
which happen to attempt, in this case, to emit QGuiApp signals.
At that point in time, the QGuiApplication ctor has not entered
the constructor body, ergo the object is still a QCoreApplication,
and calling the signal, as a member function on the derived class,
invokes UB.

Fix by cleaning up the wild mix of initialization functions used in
this hierarchy. The cleanup restores the

  1. Q*ApplicationPrivate::Q*ApplicationPrivate()
  2. Q*ApplicationPrivate::init(), calling each base class'
     init() as the first thing

two-stage construction pattern commonly used elsewhere in Qt to make
sure that the public class' object is fully constructed by the time
each level's Private::init() is called.

Change-Id: I290402b3232315d7ed687c97e740bfbdbd3ecd1a
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
2016-03-09 07:42:50 +00:00
Marc Mutz
fb7ef2b9f5 QCosmeticStroker: fix out-of-bounds access in drawPixel()
Found by UBSan:

  src/gui/painting/qcosmeticstroker.cpp:150:55: runtime error: index -1 out of bounds for type 'QT_FT_Span_ [255]'
  src/gui/painting/qcosmeticstroker.cpp:150:99: runtime error: index -1 out of bounds for type 'QT_FT_Span_ [255]'
  src/gui/painting/qcosmeticstroker.cpp:151:55: runtime error: index -1 out of bounds for type 'QT_FT_Span_ [255]'

That code path makes no sense if no span has been populated
yet, so skip the whole block if current_span == 0.

Change-Id: I832b989e89c118dc48ab5add3a28bb44c1936a76
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
2016-03-09 05:41:41 +00:00
Peter Seiderer
e69e695196 Disable c++ standard compiler flags for the host build
There is no test for c++ standard support for the host build
(only for the target compiler/build) which leads to trouble
in some cross compiling environments (old host compiler, new
cross compiler):

  g++: error: unrecognized command line option ‘-std=c++1z’

So disable c++ standard compiler flags unconditionally for host builds.

Task-number: QTBUG-51644
Change-Id: Ifb3042e125fe199a7e081740d1171d26ccacf0c5
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
2016-03-08 19:30:04 +00:00
Friedemann Kleint
4ef990ce4a tst_QKeyEvent: Fix MSVC warning about 64bit shift.
tst_qkeyevent.cpp(140): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Change-Id: Id3e0eea125f7f7ec13f9b9428e034b922d2ce204
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
2016-03-08 14:57:14 +00:00
Edward Welbourne
2d276b3ada Use booleans as booleans; don't compare == true to do so !
Change-Id: Ic900bf000cec52b3ebf0fd0fc61f42252f3200e6
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-08 13:37:27 +00:00
Edward Welbourne
5834f5a509 Purge a verbose no-op.
An if with no side-effects in its test and an empty body is a no-op.
An else block with nothing but a no-op in it is a no-op.
A no-op without even pedagogic value is just a distraction.

Change-Id: I224831a325e6b770d0a99d726d96f73da4b8c11f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-08 13:34:03 +00:00
Edward Welbourne
b366530f58 Simplified repeated #if-ery and entangled conditionals.
Three checks of the same #if managed to save repetition of (if I felt
charitable) three shared lines, compared to combining the three into
one, which leaves the code easier to read (and obviates the need for
one of the "shared" lines).  Split a long line while moving it.

Change-Id: I762d10ae1df1224c749206b8eb490bafd7ea4900
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-08 15:50:07 +00:00
Edward Welbourne
2027c0b926 Duplicate trivial code for clarity on early return.
Having a variable in which to store a function's return in two
branches of a switch in order to return if either was true saved
little relative to just testing the function in each case and
returning in situ, which reads more clearly.

Change-Id: Ibd95a95721eaa6fc4861b10e723038b96caf269a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
2016-03-08 13:25:54 +00:00
Lars Knoll
d0b54cede8 Ensure QTextStream doesn't modify the Text flag on the underlying iodevice
An empty read or a failed write on the underlying QIODevice of the text
stream would lead to an early return where we wouldn't correctly restore
the QIODevice::Text flag of the io device.

Change-Id: I5b632f45dea6ede3f408113556c3dad1b96574e2
Task-number: QTBUG-47176
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
2016-03-08 08:59:19 +00:00