QStringConverter: fix use-after-free in the stack in the test

Detected by ASan. Introduced by aef27c5aa2f43e8e34970168dfc517062cc87db8

Fixes: QTBUG-104261
Change-Id: Id0fb9ab0089845ee8843fffd16f88bdeb4f42c7c
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit 2a1122f46587e27f3d93e1f2af63f439116569c4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2022-06-14 10:10:51 -07:00 committed by Qt Cherry-pick Bot
parent 5039fec32a
commit 34a130a2da

View File

@ -351,13 +351,17 @@ void tst_QStringConverter::roundtrip_data()
} }
if (code.limitation == FullUnicode) { if (code.limitation == FullUnicode) {
const char32_t zeroVal = 0x11136; // Unicode's representation of Chakma zero using Digits = std::array<QChar, 2>;
for (int i = 0; i < 10; ++i) { using DigitsArray = std::array<Digits, 10>;
QChar data[] = { static constexpr DigitsArray chakmaDigits = []() {
QChar::highSurrogate(zeroVal + i), QChar::lowSurrogate(zeroVal + i), const char32_t zeroVal = 0x11136; // Unicode's representation of Chakma zero
}; DigitsArray r;
QTest::addRow("%s:Chakma-digit-%d", code.name, i) << QStringView(data) << code.code; 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;
} }
} }
} }