From 2a1122f46587e27f3d93e1f2af63f439116569c4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 14 Jun 2022 10:10:51 -0700 Subject: QStringConverter: fix use-after-free in the stack in the test Detected by ASan. Introduced by aef27c5aa2f43e8e34970168dfc517062cc87db8 Pick-to: 6.3 6.4 Fixes: QTBUG-104261 Change-Id: Id0fb9ab0089845ee8843fffd16f88bdeb4f42c7c Reviewed-by: Lars Knoll --- .../text/qstringconverter/tst_qstringconverter.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp index 231df0390e..633346a639 100644 --- a/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp +++ b/tests/auto/corelib/text/qstringconverter/tst_qstringconverter.cpp @@ -351,13 +351,17 @@ void tst_QStringConverter::roundtrip_data() } if (code.limitation == FullUnicode) { - const char32_t zeroVal = 0x11136; // Unicode's representation of Chakma zero - for (int i = 0; i < 10; ++i) { - QChar data[] = { - QChar::highSurrogate(zeroVal + i), QChar::lowSurrogate(zeroVal + i), - }; - QTest::addRow("%s:Chakma-digit-%d", code.name, i) << QStringView(data) << code.code; - } + using Digits = std::array; + using DigitsArray = std::array; + static constexpr DigitsArray chakmaDigits = []() { + const char32_t zeroVal = 0x11136; // Unicode's representation of Chakma zero + DigitsArray r; + for (int i = 0; i < int(r.size()); ++i) + r[i] = { QChar::highSurrogate(zeroVal + i), QChar::lowSurrogate(zeroVal + i) }; + return r; + }(); + for (int i = 0; i < int(chakmaDigits.size()); ++i) + QTest::addRow("%s:Chakma-digit-%d", code.name, i) << QStringView(chakmaDigits[i]) << code.code; } } } -- cgit v1.2.3