Commit Graph

60828 Commits

Author SHA1 Message Date
Christian Ehrlicher
834617e1d0 QTextLayout/text cursor: use the same height as the selection
The height of the selection was adjusted for high-dpi screens by a fix
for QTBUG-98372. But the height of the cursor was forgotten. This is
only visible with a very high device pixel ratio.

Pick-to: 6.5
Change-Id: I3ae9a2df0a160b50593931828cdd69c0a8d4b5c4
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
2023-03-20 20:58:08 +01:00
Dennis Oberst
d795dfaee7 Example: update wordcount example
Added a QFileDialog to let the user select a path. Before, the path
was statically assigned with "../../" , which is not optimal.
I also modified the findFiles function to check for text files in
general and not only *.cpp and *.h files. Lastly the result of the
word counting is now displayed on the console, as I think this is an
informative output from this example.

Task-number: QTBUG-111165
Pick-to: 6.5 6.5.0
Change-Id: Ie27c6acb4f79a78e3bef141edb92de08901fde71
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-20 20:58:08 +01:00
Edward Welbourne
5c2245cd66 Rework documentation of cbordump example
Focus the phrasing on what it teaches - how to use the stream reader -
more than the example application of that, displaying it.
Update docs:
* Changed name to conform to modern guidelines.
* Consistently mark \c cbodrump as code.
* Fix mentions of CborDumper and CborTagDescription to match code.
* Say how the tagDescriptions table is used.

Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: Ic12e77cf34caadc9f60527e886f94c76cb8cfeaf
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-20 19:18:53 +01:00
Edward Welbourne
074d3d54d8 Use local names to make some numeric_limits references more readable
Pick-to: 6.5
Task-number: QTBUG-111228
Change-Id: I220f5c2f13c8f01278be806c8e8d6a3a1be8e986
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-20 19:18:53 +01:00
Edward Welbourne
db5279825c Corelib: s/Q_OS_MAC/Q_OS_DARWIN/wg except for doc and definition
I got tired of being told off by the inanity 'bot for faithfully
reflecting existing #if-ery in new #if-ery. Retain only the
documentation and definition of the deprecated define.

Change-Id: I47f47b76bd239a360f27ae5afe593dfad8746538
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-03-20 19:18:52 +01:00
Edward Welbourne
adedd3f81d QTimeZone: use correct Darwin define in #if-ery
In so far as we support Darwin on tvOS or iOS, it surely makes more
sense to use the same code as on macOS for them. This will also avoid
further grumbles from the inanity 'bot about the use of the old define.

As a drive-by, make the #if-ery on newBackendTimeZone() consistently
use parentheses with defined.

Change-Id: I6099adfedfc42bba057c8cbfbb38574e2e5d80d7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-03-20 19:18:52 +01:00
Edward Welbourne
9896ebf93d Testlib: fix the last few s/Q_OS_MAC/Q_OS_DARWIN/w
Change-Id: I6fe6a865aea37c6a2d153bd2c3aace5242362c88
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
2023-03-20 19:18:52 +01:00
Joerg Bornemann
656729c5b6 CMake: Write Qt's namespace into module info JSON files
If Qt was configure with QT_NAMESPACE set, store that in the module
information files under 'built_with.namespace'.

Task-number: QTBUG-111158
Change-Id: I273309cb263c64f801dbb7238440336d7afa635e
Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-03-20 18:48:57 +01:00
Tor Arne Vestbø
1bde203605 macOS: Disable interaction for modally blocked transient parent windows
When a window-modal window has a transient ancestor, Qt treats this
ancestor window as modally blocked by the modal window, as if it had
been a true non-transient parent of the modal window.

Unfortunately, this is not how macOS natively behaves. Window-modal
windows only block their direct parent, and AppKit will happily
send events to any other top level window. This is different from
how application modal windows work, where NSApplication will filter
many events (but not all) in [[NSApplication _modalSession:sendEvent:].

Note that NSWindow.worksWhenModal has no effect in this situation,
as that property is only considered by AppKit for application
modal session are active (and NSApp.modalWidow returns non-nil).

Instead of trying to replicate the event filtering that AppKit does,
which would be fragile, we disable some of the effects these events
could potentially have, by for example preventing modally blocked
windows from becoming key, and temporarily disabling the close
button in the title bar.

One remaining issue is that, unlike with application modal windows,
the modally blocked transient parents can still be ordered above
the modal window. Fixing this requires informing the window server
about the modally blocked state of the window, which we can't do
using public APIs. Even returning NO from [NSWindow _allowsOrdering]
is not sufficient.

Task-number: QTBUG-104905
Pick-to: 6.5
Change-Id: I7e764a354f397ae6ef61304ca5442a4e1bb7589c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-20 17:39:18 +01:00
Tor Arne Vestbø
3bedeb837e macOS: Bail out if handling cut/copy/paste action from non-Qt NSMenuItem
The typical way to set up menus on macOS, which we follow, is to create
NSMenuItems with an action selector set (copy:), but without a target.
This will result in AppKit finding a target dynamically, starting with
the first responder, walking the responder chain, and then moving on
to other NSWindows, before ending up in the NSApplication and its
delegate.

Unfortunately, we don't have a mechanism in Qt to forward generic
actions, such as the cut/copy/paste, or selectAll, so we rely on
mapping the actions back to QCocoaNSMenuItem that we can trace
back to a QPlatformMenuItem that we in turn emit activated() for.

Normally this works fine, but in the case where the Qt app is embedded
in a native UI, which has its own menu items with cut/copy/paste,
we'll get callbacks into QNSView for actions triggered by a generic
NSMenuItem.

In that case, we need to bail out, but we must do so without calling
[super forwardInvocation:invocation], as that will just try to invoke
the action on ourselves again.

It's unfortunately too late to try to redirect the action to another
responder, that might have handled the action, and it's questionable
whether that would be the behavior we'd want, as that would possibly
result in e.g. pasting text into another window than the Qt one that
currently has an active cursor in a text entry.

Fixes: QTBUG-111916
Pick-to: 6.5
Change-Id: I56318e4f7efd779cd20bf577aec8c2de04a6a142
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-20 17:39:18 +01:00
Tor Arne Vestbø
391491c8b3 macOS: Add logging category for menu machinery
The machinery is quit fragile, so any logging will help here.

Pick-to: 6.5
Change-Id: I1906c0e33b4afbf649a20bfe2aa7210b6822087e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-20 17:39:18 +01:00
Mårten Nordheim
6a66554d3b Revert "Skip socket and server tests on Ubuntu 22.04 and QEMU"
This reverts commit 9286d46ee2.

Reason for revert: Should be fixed by 5c6814fb18760f65bab0f8b9cd623ee5c874a58d

Change-Id: I3a161df445af8dcbb61138d57e931a093a319027
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2023-03-20 17:39:18 +01:00
Ievgenii Meshcheriakov
2834d4263a remotecontrolledcar example: Move car.xml to common directory
It is shared between car and controller executables.

Task-number: QTBUG-111366
Pick-to: 6.5
Change-Id: I5f98a09664671c55bfad68ebf88c9f0c734511fa
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-20 17:15:00 +01:00
Ievgenii Meshcheriakov
5cd7900d4f remotecontrolledcar example: Move executables into single example project
This allows building of all the example executables at once.

Task-number: QTBUG-111366
Pick-to: 6.5
Change-Id: I1fa372ec9725bfeb1f123305aa7324b7820eb593
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-20 17:14:59 +01:00
Marc Mutz
f4f49523ad tst_QMessageAuthenticationCode: avoid setKey() calls
We test setKey() in repeated_setKey() these days, so speed up the test
of the test suite ever so slightly by passing the key to the ctor
instead of an explicit setKey() call.

Pick-to: 6.5
Change-Id: Ia2378c0f59cbfa9d95a0f3665b06655332247e2c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-20 14:42:11 +01:00
Marc Mutz
a011e47f3d QMessageAuthenticatonCode: re-use QCryptographicHash's result buffer
QMessageAuthenticationCodePrivate::result always mirrored
QCryptographicHash's, so we only need one, greatly reducing
sizeof(QMessageAuthentcationCodePrivate) and avoiding unnecessary
copies.

Pick-to: 6.5
Change-Id: I56365b29bd9e096a4582b1764b6fef4c5243735b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-20 14:42:11 +01:00
Piotr Wierciński
c6e04356d4 Wasm: Fix displaying frameless QWasmWindow with transparent content
Currently we render shadow and default background-color even for
frameless windows with transparent content.
This behavior is not consistent comparing to other platforms.

An example of such window is InputSelectionHandle from
VirtualKeyboard module.

This commit disables shadow-box and provides transparent
background-color for QWasmWindow which are frameless.
It also provides distinction between "frame" as logic property
of window and "border" as visual decoration.

Change-Id: I902692ea561a2e88e2e6ab7faad8e3eeb536a26b
Reviewed-by: Aleksandr Reviakin <aleksandr.reviakin@qt.io>
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
2023-03-20 13:03:44 +01:00
Kai Köhne
003b084f38 Centralize copyright information for Qt
Maintain one central place - .cmake.conf - for information
about Qt's copyright.

Pick-to: 6.2 6.5
Change-Id: Ibcbce4313eba9660d459061b0ad00307e267b8f7
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2023-03-20 13:03:44 +01:00
Kai Köhne
70bc5dcb75 Update Copyright year to 2023
Pick-to: 5.15 6.2 6.5
Change-Id: I8812bf2523ccb715407181aec6aebf2034c8ff84
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-20 12:03:44 +00:00
Marc Mutz
ed604ce101 QMessageAuthenticationCode: remove Private::method
...it's the same as messageHash.method, so we don't need to store it
twice.

Pick-to: 6.5
Change-Id: I926dbfa177c25e9bc3ebed9149da5ce8bad8cf2f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-20 09:12:37 +01:00
Marc Mutz
57a7db746a QMessageAuthenticationCode: reuse messageHash mutex
QMessageAuthenticationCode operates the embedded QCryptographicHash in
an unshared way, in which QCryptographicHashPrivate::finalizeMutex is
never used. So kick QMessageAuthenticationCodePrivate::finalizeMutex
out and use QCryptographicHashPrivate::finalizeMutex instead.

The only effect it the reduction in QMessageAuthenticationCodePrivate
size by sizeof(QBasicMutex).

Pick-to: 6.5
Change-Id: I02208eb42f8247939619f74ad3e040cb0d34b5ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-20 08:12:33 +00:00
Ahmad Samir
f6b780b583 QtMiscUtils: add isAsciiPrintable() helper
- isAsciiPrintable: borrowed the logic from isPrintable(uchar) in
  qdebug.cpp, now isPrintable(uchar) calls isAsciiPrintable

- Replace ::isspace() with ascii_isspace() from qlocale_p.h

Functions from ctype.h have a couple of issues:
- they're locale-dependent, which isn't what's required here, the code
  is only interested in ASCII
- their args should be representable as uchar or EOF otherwise it's
  undefined behavior

An Early-Warning could use something like:
grep -rP "\b(isalnum|isalpha|isblank|iscntrl|isdigit|islower|isgraph|\
         "isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper)\b"

Pick-to: 6.5
Task-number: QTBUG-111262
Change-Id: I1f47f41bd56735297078ff0d0ddc2ebf999abf8b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-18 12:00:56 +02:00
Christian Ehrlicher
d184c66ad5 SQL/Tests: Cleanup of tst_databases.h
Cleanup tst_databases.h: fix identation, replace qGetHostName() with
QSysInfo::machineHostName(), use QSqlTableModel::EditStrategy instead
int for submitpolicy data to avoid casts.

Change-Id: I4917ca23c4b39ab15bc0e006e6111baefb82d278
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 23:08:44 +01:00
Christian Ehrlicher
17e4b2d8ed SQLite: Update SQLite to v3.41.1
[ChangeLog][QtSQL][SQLite] Updated SQLite to v3.41.1

Pick-to: 5.15 6.2 6.5 6.5.0
Change-Id: Ibc88ae7b73ea46797d7aff00ee193b1ccfaae31b
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
2023-03-17 22:30:06 +01:00
Christian Ehrlicher
acb6131a4d SQL/IBASE: fix tests
Fix some tests so they will correctly work with Interbase (Firebird 3.x)

Change-Id: Ib3c8ceaf31fa01af3a00a9772350b49cee8b2342
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 20:33:16 +01:00
Christian Ehrlicher
1981ebe8ad SQL/OCI: add maximumIdentifierLength()
A table name or identifier must not be longer than 30 (< Oracle 12.2) or
128 bytes (sadly not characters).

Change-Id: I49192afaf908e12f5cfd20c754640b6117b03a71
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 20:33:16 +01:00
Christian Ehrlicher
f49f3f2f94 SQL/Tests: Cleanup tst_QSqlDatabase
Remove driverQuotedCaseSensitive() as it's no longer needed, fix view
creation for PostgreSQL.

Change-Id: I72437252cfad762a5a245475d6652de3c7b5ef46
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 20:33:15 +01:00
Christian Ehrlicher
dfe317f552 SQL/IBASE: misc cleanup
Misc cleanup of the IBASE driver - use qsizetype and range-based for
loops.

Change-Id: I69fe8ed3303fb352b59989c625de5a51239cf604
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 19:14:58 +01:00
Axel Spoerl
b04f9388ac QColorDialog: Support hex rgb values with and without leading #
QColorDialog supports entering hex rgb values only with a leading #.
That makes copy/paste impossible whenever the copy source has plain
hex, without the leading #.

This patch automatically adds a leading # character, when missing.
As a drive-by, QObject::connect statements are altered to PTMF syntax,
amending 9eb1b9e86ce3d1004e39e8ab7c7ecb6796d6df1a.

The patch also adds an autotest for the new functionality.

Fixes: QTBUG-111742
Pick-to: 6.5
Change-Id: I4ced29dc8b543457f411a3fa0ac756b550cdb09f
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-17 18:06:28 +01:00
Timur Pocheptsov
f03fedfaec Revert "QCocoaMenuBar: avoid duplication of 'special' entries in the 'Edit' menu"
This reverts commit 6c2387571a.

Caused a regression when the edit menu did not have any entries from
the system. Fixing that regression (out of bound index, crash), revealed
that the original patch is simply not working anymore - items are still
duplicated anyway.

Fixes: QTBUG-111798
Pick-to: 6.5
Change-Id: Id4a88f30e2cf300bc63181c4bc7aa113a8b13ac6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-03-17 16:19:51 +00:00
Eskil Abrahamsen Blomfeldt
5c7a3ea783 doc: Add note about platform support for window positions
On some platforms, such as Wayland (and also eglfs), manual window
positioning is not supported. Since this has caused confusion in the
past, we add a note to the documentation.

Pick-to: 6.2 6.5
Fixes: QTBUG-86780
Change-Id: Idf8dcdfad8ccfb9eb0f704fce05216562e433e20
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2023-03-17 16:01:27 +01:00
Santhosh Kumar
f50b853bed Adjust window rectangle for menu baseline test case
Capturing complete window for menu test cases makes it fail as there can
be different window shapes (such as rectangular or rounded corners). To
avoid this, its better to capture only minimal visual portion that can
be compared against.

Change-Id: I30e85589fce8c17115f511a7a345d46949e6c9e8
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 15:50:30 +01:00
Santhosh Kumar
ee3611ce91 Remove window frame for combo-box widget baseline test case
The window frame differs across ms-windows version and this makes
combobox test case either fail or more fuzzy. To avoid this provide
only window geometry for screen capture instead of complete window
rectangle.

Change-Id: I0f1a1a95c45218ccc69fc92f589baee0135db943
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-17 15:03:13 +01:00
David Redondo
141d626029 Handle device loss for texture widgets
Previously the widget stayed black and we printed
"QBackingStoreDefaultCompositor: the QRhi has changed unexpectedly,
this should not happen".
To make it work the compositor is recreated in addition to the rhi
and the  widgets are informed with the internal events.

Change-Id: I982d08bd3530478fe0f827080154c008a92a812e
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-17 14:45:21 +01:00
Edward Welbourne
b538a53a9d Silence a signed vs unsigned warning when char is signed
Change-Id: I5f706f87f3a15f3723a2d4ce3044b84b924da3e5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-17 13:59:18 +01:00
Piotr Wierciński
d8e483170e Wasm testing: Refactor test framework and update tests
Update tests so they take into account minimum QWasmWindow size
constraints.
Refactor test framework and make it easier to read and write new tests.

Change-Id: I621c5eee6577f1569eef93e883d1cf0828e3946f
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
2023-03-17 12:16:41 +00:00
Morten Sørvig
24ebb172c3 wasm: export qstdweb::readDataTransfer()
Fix shared libraries build.

Change-Id: I7bf1c7d333b7d039905ee77cf954ba46549993d3
Reviewed-by: Mikołaj Boc <Mikolaj.Boc@qt.io>
2023-03-17 09:14:00 +00:00
Thiago Macieira
82b75570f0 QProcess/Linux: fix file descriptor leak in case of failed child start
If the child failed to start, execChild() would (unnecessarily) store -1
in childStartedPipe[1] after writing the failure message to it and
closing that pipe. This had worked for the previous 20 years of QProcess
existence, because that was run in the child process. However, with 6.5
commit e1a787a76e (cherry-picked to 6.4)
we implemented vfork-like behavior, meaning the child would share memory
with the parent and ran before the parent, so startProcess() failed to
close it:

    // parent
    // close the ends we don't use and make all pipes non-blocking
    qt_safe_close(childStartedPipe[1]);

Also updated the docs to account for the fact that this is a vfork()
environment and, moreover, not using the vfork() function from glibc on
Linux.

[ChangeLog][QtCore][QProcess] Fixed a file descriptor leak in QProcess
when running on Linux 5.4 or later, if the executable being run failed
to start (for example, the file for the executable didn't exist).

Pick-to: 6.4.3 6.4 6.5
Task-number: QTBUG-111243
Change-Id: I7f354474adce419ca6c2fffd17481002e4853cc3
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-16 16:26:47 -08:00
Marc Mutz
96dc4acb23 QCryptographicHash: check addData() with null QByteArrayView
When this code was using QByteArray, whose data() is never nullptr,
the strings presented to the underlying C APIs were always valid NTSs
(nullptr is not a valid NTS).

With QByteArrayView, or with QT5_NULL_STRINGS != 1, this is no longer
the case. Check that all implementations are fine with that.

Pick-to: 6.5 6.4
Change-Id: I78251288a4784440af4a2daf095aed7c53867287
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:33 +01:00
Marc Mutz
e80fc16cec QCryptographicHash: move EVP struct into the contexts union
... making it just another context.

Well, except the EVP struct has non-trivial SMFs, so adding it to the
union deletes all the union's SMFs, too. To restore them, we need to
give the union a class name (State). Since we anyway need to provide
ctors, inline all init() functions into them.

State having a ctor means we need to call it, with the method
argument, in the Private ctor-init-list. That requires the State
member to have a name.

Since the union thus no longer defines variant members within Private,
move most of the functions that operated on the variant members into
State or EVP to avoid having to sprinkle state./evp.-prefixes all over
the code.

This gives the opportunity to re-share some code that was duplicated
when we dragged #ifdef USING_OPENSSL3 out of the functions into
namespace scope. The move of the functions into State robs them of
their access to other Private members, to wit, 'method' and 'result',
so we have to pass them as arguments now.

I tried to split this up into smaller patches, but it kinda has to
happen all at once, sorry.

Pick-to: 6.5
Change-Id: If864d4d46075d00420f6e849cd68c4b824c1a50a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:33 +01:00
Marc Mutz
b1919f01c8 QCryptographicHash: move EVP members into a struct
... and move the evp_{init,reset,finalizeUnchecked}() functions into
it as new members without the evp_ prefix. Need to pass QCHPrivate
members as function arguments now.

This is in preparation of moving these members into the union.

Pick-to: 6.5
Change-Id: I64805d8aac91f777fbc5c13b1a08b37e5227169a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:32 +01:00
Marc Mutz
51b1a9963d QCryptographicHash: separate EVP and non-EVP OpenSSL3 operations
These, too, will end up on different classes, eventually. The
addData() function is the odd one out here, as it's EVP part it
trivial.

Pick-to: 6.5
Change-Id: I24c7334edd8ba218e4cfcb64d0ed67bc281c4525
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:32 +01:00
Marc Mutz
9248d0cfbe QCryptographicHash: separate OpenSSL3 and traditional modes more
... by defining separate init(), reset(), addData() and
finalizeUnchecked() functions instead of doing #ifdef'ery inside the
function bodies.

The purpose of the exercise is that these functions will later end up
in different classes. For now, we can already drop the UINT_MAX loop
for the OpenSSL30 case, as both EVP_DigestUpdate() and the Blake
functions use size_t lengths in the API.

Pick-to: 6.5
Change-Id: I9ad618c90bb54b429db3225061cd5cfd25243fca
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-17 00:41:32 +01:00
Marc Mutz
ca1b03be69 QCryptographicHash: split initialization from reset()ing
Before the OpenSSL3 mode was added, these operations were the
same. The placement-new of the active union member was arguably not
even necessary, as just naming it should start their lifetime;
certainly all initialization was vacuous, anyway. So it didn't really
matter that we re-did it on each reset().

But OpenSSL3 mode is different: initialization allocates (and can
fail) whereas reset() does not¹, so it makes sense to separate them,
so as to re-establish the lost proper noexcept'ness of reset().

¹ or so we assume

This will also help when moving the EVP members into the union later.

Pick-to: 6.5
Change-Id: Id1c9a00cddb95fb2235162409c2301dd4c35228a
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:32 +01:00
Marc Mutz
4ac7ac5b59 QCryptographicHash: fix missing EVP_DigestInit_ex() after EVP_MD_CTX_reset()
EVP_MD_CTX_reset() alone is not sufficient. A following
EVP_DigestUpdate() crashes, so re-init the context, too.

Amends 189444d8c4.

Pick-to: 6.5
Change-Id: I5dede0adddd7f6b0c62540f6d45917b3236e3d02
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2023-03-17 00:41:32 +01:00
Marc Mutz
a6bf36d409 QMessageAuthenticationCode: make reset() noexcept
This is the last method that can and should be noexcept:

- the ctor allocates the Private, so can't be
- static hash() allocates QByteArray::data(), so also cannot be
- ditto result()

All other functions are already noexcept.

Fixes: QTBUG-111688
Change-Id: I237c3d1292452da5ca92712531c3527c1fb2f59b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:32 +01:00
Marc Mutz
c19f9716fb QMessageAuthenticationCode: port to QByteArrayView [3/3]: static hash()
The class is not used frequently enough to warrant the overhead of a
Q_WEAK_ QByteArray overload to fix the SiC Type A for users that pass
objects that implicitly convert to QByteArray, esp. since we'd need
_four_ overloads to handle the two byte array arguments here, and
still cause ambiguities, because there's only one level of "weakness"
in Q_WEAK_OVERLOAD, but we'd need two.  QCryptographicHash::hash()
also doesn't have it.

[ChangeLog][QtCore][QMessageAuthenticationCode] The constructor,
setKey(), addData() methods as well as the static hash() function take
arguments by QByteArrayView instead of QByteArray now.

[ChangeLog][Potentially Source-Incompatible Changes] More APIs now
take QByteArrayView instead of QByteArray. You will now get a compile
error when your code passes to such functions objects that implicitly
convert to QByteArray, but not QByteArrayView. Wrapping such arguments
in QByteArray{~~~} to make the cast explicit is a backwards-compatible
way to avoid this problem.

Fixes: QTBUG-111676
Change-Id: Iaff832df3b315ca2eee7bff93720b6681182036f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:32 +01:00
Marc Mutz
6a6e9337c7 QMessageAuthenticationCode: port to QByteArrayView [2/3]: addData()
The class is not used frequently enough to warrant the overhead of a
Q_WEAK_ QByteArray overload to fix the SiC Type A for users that pass
objects that implicitly convert to QByteArray. QCryptographicHash also
doesn't have it.

Also mark addData() noexcept. Now that it takes a view instead of
an owning container, it only calls other noexcept functions.

Make the new overload carry actual documentation instead of just
\overload.

ChangeLog will be on patch [3/3].

Task-number: QTBUG-111676
Task-number: QTBUG-111688
Change-Id: Ie6447bf54d7d442b1a76761bc0f28f868c08ef09
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:32 +01:00
Marc Mutz
93cb61e305 QMessageAuthenticationCode: port to QByteArrayView [1/3]: ctor/setKey()
The class is not used frequently enough to warrant the overhead of a
Q_WEAK_ QByteArray overload to fix the SiC Type A for users that pass
objects that implicitly convert to QByteArray. QCryptographicHash also
doesn't have it.

Also mark setKey() noexcept. Now that it takes a view instead of
an owning container, it only calls other noexcept functions.

ChangeLog will be on patch [3/3].

Task-number: QTBUG-111676
Task-number: QTBUG-111688
Change-Id: Ic2321d0d41ce8eb4d0390889f28b3fd4bd9af103
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-17 00:41:31 +01:00
Allan Sandfeld Jensen
0cab9b56e9 Fix UBSAN warnings
Convert tagged pointer to an encapsulated tagged pointer type, and clean
up where it is used.

Change-Id: I9cf5b8d1dfa345eebaa185e44d762d5008769480
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-17 00:41:31 +01:00