summaryrefslogtreecommitdiffstats
path: root/examples/qtestlib/tutorial4/testgui.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-08-18 17:24:34 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-09-07 15:15:28 +0200
commitf020c4ba51e257915837f2672cc37b5ac3f51936 (patch)
tree204bf74cbf7bf3e69fbfcfd1e8624937e707f75c /examples/qtestlib/tutorial4/testgui.cpp
parent66b633bbc1f9dd27825eb87030dbad134c1d24c8 (diff)
QIODevice: fix narrowing conversions in debugBinaryString
The debugBinaryString() function is a hexedit-like pretty-printer which prints in increments of 16 octets, so it can go forever. The old code had an overload set (QByteArray) and (ptr, qint64 size), but made the (ptr, n) overload construct a QByteArray to call the QBA overload. That's a narrowing conversion right there, except it can't trigger because no machine can hold that much memory. But it may warn. The code inside went on with further narrowing conversions to int, this time, which does have an effect on 64-bit. Granted, you'd wait a long time for this inefficient pretty-printer to write out more than 16Mi lines of hex dump, but it's wrong nonetheless, because narrowing conversions work with modulo arithmetic and not saturation arithmetic, so passing a buffer of INT_MAX + 1 size would print nothing, which would probably cause some time lost hunting unrelated bugs. So, fix the whole thing as follows: - remove the QBA overload, it was never called - loop over the full range of up to LLONG_MAX characters; if developers pass too much data, that's SEP - remove the narrowing casts to qsizetype at the call sites (avoids modulo arithmetic) As a drive-by, make the function static, and to get compilers to actually see all this, make it [[maybe_unused]] instead of ifdef'ing out. Not picking back, as it's debug-only code. Task-number: QTBUG-103525 Change-Id: I8b06466365d8c57b14535d8752428a614f244297 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'examples/qtestlib/tutorial4/testgui.cpp')
0 files changed, 0 insertions, 0 deletions