Commit 51a56fa6 authored by Milian Wolff's avatar Milian Wolff
Browse files

Fix another situation where we could go past-end in ParamIterator

When we set m_curEnd to the end but m_cur is left at a previous stage,
we would end up dereferencing past the end of the string in operator++

Fixes:
```
Using QCharRef with an index pointing outside the valid range of a QString.
The corresponding behavior is deprecated, and will be changed in a future version of Qt.
```
parent 28749545
......@@ -657,7 +657,10 @@ ParamIterator& ParamIterator::operator ++()
Q_ASSERT(*this);
if (d->m_source[d->m_curEnd] == d->m_parens[1]) {
if (d->m_curEnd >= d->m_source.size()) {
//We have reached the end-paren. Stop iterating.
d->m_cur = d->m_end = d->m_curEnd;
} else if (d->m_source[d->m_curEnd] == d->m_parens[1]) {
//We have reached the end-paren. Stop iterating.
d->m_cur = d->m_end = d->m_curEnd + 1;
} else {
......
......@@ -163,6 +163,9 @@ void TestStringHelpers::testParamIterator_data()
addTest("Y<decltype(&X::operator->), Z<&X::operator->>>", {"decltype(&X::operator->)", "Z<&X::operator->>"});
addTest("Y<decltype(&X::operator--), &X::operator-->", {"decltype(&X::operator--)", "&X::operator--"});
addTest("Y<decltype(&X::operator--), Z<&X::operator-->>", {"decltype(&X::operator--)", "Z<&X::operator-->"});
addTest("Y<decltype(&X::operator<=), Z<&X::operator<=>>", {"decltype(&X::operator<=)", "Z<&X::operator<=>"});
// NOTE: this identifier here is invalid but we shouldn't trigger UB either, so the test is just that we get _something_ (even if it's wrong)
addTest("bogus<_Tp, _Up, invalid<decltype(<=(std::declval<_Tp>(), std::declval<_Up>()))>>", {"_Tp", "_Up", "invalid<decltype(<=(std::declval<_Tp>(), std::declval<_Up>()))>>"});
}
void TestStringHelpers::testParamIterator()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment