summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2016-05-18 08:50:53 +0200
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2016-05-18 10:34:13 +0000
commit27425e62c071441fa8ef34775b6ad7d985e07fde (patch)
treed2753c99ab8d200811637c54e2d1bb597bd2f0a2 /src/tools
parent4251509c2d7af3ae691350b4bae7fcbd7773d8c6 (diff)
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>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/moc/preprocessor.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index a2a1a958cf..bfe61d0895 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -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