Details
-
Bug
-
Resolution: Done
-
P2: Important
-
None
-
6.3.0
-
None
-
-
5
-
4712b0cd70 (qt/qtbase/6.3) 4712b0cd70 (qt/tqtc-qtbase/6.3)
-
Team B Foundation Sprint 59
Description
Documentation:
qsizetype QString::indexOf(const QRegularExpression &re, qsizetype from = 0, QRegularExpressionMatch *rmatch = nullptr) const
Returns the index position of the first match of the regular expression re in the string, searching forward from index position from. Returns -1 if re didn't match anywhere.
If the match is successful and rmatch is not nullptr, it also writes the results of the match into the QRegularExpressionMatch object pointed to by rmatch.
It should mention that the QString in question must remain valid as long as rmatch is used.
QRegularExpressionMatch has constructors for both QString and QStringView and user of this function does not know which one is used. With just reading documentation of this function, it's very easy to write code that accesses deleted memory and results in random bugs:
QRegularExpressionMatch match;
if (getString().indexOf(QRegularExpression("m[aeiou]"), 0, &match) != -1)
OR
QRegularExpressionMatch match;
QString str = getString();
if (str.left(5).indexOf(QRegularExpression("m[aeiou]"), 0, &match) != -1)
Attachments
For Gerrit Dashboard: QTBUG-103940 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
421126,1 | QString: fix lifetime issues with QRegularExpression APIs | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: NEW | 0 | 0 |
420423,3 | QString: fix lifetime issues with QRegularExpression APIs | dev | qt/qtbase | Status: MERGED | +2 | 0 |
421122,2 | QString: fix lifetime issues with QRegularExpression APIs | 6.4 | qt/qtbase | Status: MERGED | +2 | 0 |
421123,2 | QString: fix lifetime issues with QRegularExpression APIs | 6.3 | qt/qtbase | Status: MERGED | +2 | 0 |