Work around GCC 13's bogus "out of bounds" check to QByteArray::_empty

Nothing here is empty and even if anything were, QStringBuilder properly
handles empty strings.

In static member function ‘static void QConcatenable<QByteArrayView>::appendTo(QByteArrayView, char*&)’,
    inlined from ‘static void QConcatenable<QStringBuilder< <template-parameter-1-1>, <template-parameter-1-2> > >::appendTo(const type&, T*&) [with T = char; A = QByteArrayView; B = const char (&)[20]]’ at qstringbuilder.h:398:37,
    inlined from ‘T QStringBuilder< <template-parameter-1-1>, <template-parameter-1-2> >::convertTo() const [with T = QByteArray; A = QByteArrayView; B = const char (&)[20]]’ at qstringbuilder.h:117:54,
    ...
qstringbuilder.h:178:19: error: ‘void* memcpy(void*, const void*, size_t)’ forming offset [1, 5] is out of the bounds [0, 1] of object ‘QByteArray::_empty’ with type ‘const char’ [-Werror=array-bounds=]

QStringBuilder::convertTo() creates the target as
        const qsizetype len = QConcatenable< QStringBuilder<A, B> >::size(*this);
        T s(len, Qt::Uninitialized);

We know len can't be zero because GCC is complaining about a memcpy()
when the offset has been changed from 0, meaning QByteArray was given a
non-zero size and therefore its data pointer is not &QByteArray::_empty.

Fixes: QTBUG-116763
Pick-to: 6.5 6.6
Change-Id: I85599ea5ca7a4b79a8bbfffd178af437984080fb
Reviewed-by: Shawn Rutledge (away) <shawn.rutledge@qt.io>
bb10
Thiago Macieira 2023-10-04 09:25:29 -07:00
parent eedb715ece
commit 9aaf12ebaa
1 changed files with 3 additions and 0 deletions

View File

@ -99,6 +99,8 @@ QList<QByteArray> supportedImageFormats(Capability cap)
static constexpr QByteArrayView imagePrefix() noexcept { return "image/"; }
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Warray-bounds") // QTBUG-116763
QList<QByteArray> supportedMimeTypes(Capability cap)
{
QList<QByteArray> mimeTypes;
@ -114,6 +116,7 @@ QList<QByteArray> supportedMimeTypes(Capability cap)
mimeTypes.erase(std::unique(mimeTypes.begin(), mimeTypes.end()), mimeTypes.end());
return mimeTypes;
}
QT_WARNING_POP
QList<QByteArray> imageFormatsForMimeType(QByteArrayView mimeType, Capability cap)
{