Moc: fix crash when a file ends with \\\r
make the 'cleaned' more robust by making sure we do not read past the buffer in some cases. We must also use resize and not reserve on the outpt buffer because reseve is meant as a hint and we are not supposed to write past the size of the QByteArray even if it is reserved. [ChangeLog][moc] Fixed crash on file ending with \\\r Task-number: QTBUG-53441 Change-Id: I901e6c0ffc7f8877de3d07fd08cf26495461d294 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com> Reviewed-by: Robert Loehning <robert.loehning@qt.io>
This commit is contained in:
parent
4251509c2d
commit
27425e62c0
@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE
|
||||
static QByteArray cleaned(const QByteArray &input)
|
||||
{
|
||||
QByteArray result;
|
||||
result.reserve(input.size());
|
||||
result.resize(input.size());
|
||||
const char *data = input.constData();
|
||||
const char *end = input.constData() + input.size();
|
||||
char *output = result.data();
|
||||
@ -78,13 +78,15 @@ static QByteArray cleaned(const QByteArray &input)
|
||||
if (data != end && (*(data + 1) == '\n' || (*data) == '\r')) {
|
||||
++newlines;
|
||||
data += 1;
|
||||
if (*data != '\r')
|
||||
if (data != end && *data != '\r')
|
||||
data += 1;
|
||||
continue;
|
||||
}
|
||||
} else if (*data == '\r' && *(data + 1) == '\n') { // reduce \r\n to \n
|
||||
++data;
|
||||
}
|
||||
if (data == end)
|
||||
break;
|
||||
|
||||
char ch = *data;
|
||||
if (ch == '\r') // os9: replace \r with \n
|
||||
|
@ -57,3 +57,5 @@ public slots:
|
||||
#undef value
|
||||
|
||||
#endif // BACKSLASH_NEWLINES_H
|
||||
|
||||
// ends with \\\r should not make moc crash (QTBUG-53441) (no new lines on purpose!!) \
|
Loading…
Reference in New Issue
Block a user