From 3c1b01ec3e3aa4c73ad5b2749f1fa0c949e4f7c9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 4 Mar 2025 12:22:06 +0100 Subject: [PATCH] ucstricmp8: fix Coverity ARRAY_VS_SINGLETON issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Coverity has this checker where it complains if you use a T as a T[1]. The C++ standard says this is fine¹, but qstring.cpp, specifically, is security-critical, so we shouldn't leave Coverity issues unfixed in there. So replace uc1 with a decoded[1] array and make both output and uc1 point to decoded's first (and only) element. Amends 45838673df6e64a6fd42570c4e8874c5181f7717. ¹ https://eel.is/c++draft/basic.compound#3.sentence-11 Pick-to: 6.8 6.5 Coverity-Id: 378348 Change-Id: Ib149386defd8b263df522a4f12b1af1b3fc1a20c Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira (cherry picked from commit 4eb9e0d3eedfc1b6de968308167af01b19f6ffe7) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qstring.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index fe8781bc003..10f481fce7e 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -1243,8 +1243,9 @@ Q_NEVER_INLINE static int ucstricmp8(const char *utf8, const char *utf8end, cons QStringIterator src2(utf16, utf16end); while (src1 < end1 && src2.hasNext()) { - char32_t uc1 = 0; - char32_t *output = &uc1; + char32_t decoded[1]; + char32_t *output = decoded; + char32_t &uc1 = decoded[0]; uchar b = *src1++; const qsizetype res = QUtf8Functions::fromUtf8(b, output, src1, end1); if (res < 0) {