diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-06-10 16:57:52 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-06-14 01:31:05 +0000 |
commit | e2500fd5d63bbb7d998bcc3ab876eea39c7d5ab5 (patch) | |
tree | 3e2af2b501cf0c04012c3622740c3e9e6a47c79d /src/corelib | |
parent | ff54eed29242fade7774cc1a954ec83182c14535 (diff) |
QByteArray: more GCC 12 -Werror=array-bound whack-a-mole
This one came up on a tsan build, but not on an asan/ubsan one!?!:
qbytearray.cpp: In member function ‘QByteArray QByteArray::toBase64(Base64Options) const’:
qbytearray.cpp:3884:42: error: array subscript 1 is outside array bounds of ‘const char [1]’ [-Werror=array-bounds]
3884 | chunk |= int(uchar(data()[i++])) << 8;
| ~~~~~~~~~~^
qbytearray.cpp:37:24: note: at offset 1 into object ‘QByteArray::_empty’ of size 1
37 | Q_CONSTINIT const char QByteArray::_empty = '\0';
| ^~~~~~~~~~
cc1plus: all warnings being treated as errors
Fix, as so often, by caching the size().
The code in 5.15 is different, but similar, so picking all the way.
Task-number: QTBUG-103923
Change-Id: Iac30e964c8d7d367620d16db65ceeaade33ee6b4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit de005e7976e4b110d6b5f32a8bab5141713acb7b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 1219b3d86d..bb517e3a53 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -3870,19 +3870,21 @@ QByteArray QByteArray::toBase64(Base64Options options) const const char padchar = '='; qsizetype padlen = 0; - QByteArray tmp((size() + 2) / 3 * 4, Qt::Uninitialized); + const qsizetype sz = size(); + + QByteArray tmp((sz + 2) / 3 * 4, Qt::Uninitialized); qsizetype i = 0; char *out = tmp.data(); - while (i < size()) { + while (i < sz) { // encode 3 bytes at a time int chunk = 0; chunk |= int(uchar(data()[i++])) << 16; - if (i == size()) { + if (i == sz) { padlen = 2; } else { chunk |= int(uchar(data()[i++])) << 8; - if (i == size()) + if (i == sz) padlen = 1; else chunk |= int(uchar(data()[i++])); |