From d7d6f46324c7dbcfb02ddea3ab1b8db433c9b0d0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Apr 2022 10:22:52 -0700 Subject: [PATCH] Fix build with GCC12: avoid QCborStreamReader::preparse() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GCC 12 doesn't like that we're calling preparse() on the empty QByteArray() (whose .data() == &QByteArray::_empty), despite the condition being impossible. Reported at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105348 In function ‘void* qt_cbor_decoder_read(void*, void*, size_t, size_t)’, inlined from ‘void* read_bytes_unchecked(const CborValue*, void*, size_t, size_t)’ at cborinternal_p.h:234:51, inlined from ‘uint32_t read_uint32(const CborValue*, size_t)’ at cborinternal_p.h:271:25, inlined from ‘uint64_t _cbor_value_decode_int64_internal(const CborValue*)’ at cborparser.c:333:23, inlined from ‘uint64_t _cbor_value_extract_int64_helper(const CborValue*)’ at cbor.h:372:50, inlined from ‘void QCborStreamReader::preparse()’ at qcborstreamreader.cpp:769:59, inlined from ‘QCborStreamReader::QCborStreamReader(const QByteArray&)’ at qcborstreamreader.cpp:825:13, inlined from ‘QCborStreamReader::QCborStreamReader()’ at qcborstreamreader.cpp:790:37, inlined from ‘QtPrivate::QMetaTypeForType::getDefaultCtr()::’ at qmetatype.h:2302:65, inlined from ‘static constexpr void QtPrivate::QMetaTypeForType::getDefaultCtr()::::_FUN(const QtPrivate::QMetaTypeInterface*, void*)’ at qmetatype.h:2302:20: qcborstreamreader.cpp:706:18: error: array subscript ‘unsigned int[0]’ is partly outside array bounds of ‘const char [1]’ [-Werror=array-bounds] qbytearray.h:92:23: note: object ‘QByteArray::_empty’ of size 1 Pick-to: 6.2 6.3 Change-Id: If05aeeb7176e4f13af9afffd16e8485d34e36100 Reviewed-by: Ulf Hermann --- src/corelib/serialization/qcborstreamreader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/serialization/qcborstreamreader.cpp b/src/corelib/serialization/qcborstreamreader.cpp index cf90f3e397..273941214b 100644 --- a/src/corelib/serialization/qcborstreamreader.cpp +++ b/src/corelib/serialization/qcborstreamreader.cpp @@ -565,7 +565,7 @@ public: CborValue currentElement; QCborError lastError = {}; - QByteArray::size_type bufferStart; + QByteArray::size_type bufferStart = 0; bool corrupt = false; QCborStreamReaderPrivate(const QByteArray &data) @@ -787,7 +787,7 @@ inline void QCborStreamReader::preparse() \sa addData(), isValid() */ QCborStreamReader::QCborStreamReader() - : QCborStreamReader(QByteArray()) + : d(new QCborStreamReaderPrivate({})), type_(Invalid) { }