From aefadce667bde4f71ff095e675da48dfa025cc78 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 1 Dec 2019 09:57:47 +0000 Subject: [PATCH] massif-visualizer: avoid possible null-terminated string issues Signed-off-by: Ivailo Monev --- massif-visualizer/massifdata/parserprivate.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/massif-visualizer/massifdata/parserprivate.cpp b/massif-visualizer/massifdata/parserprivate.cpp index 2326ec01..a090d1de 100644 --- a/massif-visualizer/massifdata/parserprivate.cpp +++ b/massif-visualizer/massifdata/parserprivate.cpp @@ -40,7 +40,7 @@ using namespace Massif; static QByteArray midRef(const QByteArray& line, int offset, int length = -1) { - return QByteArray::fromRawData(line.data() + offset, length == -1 ? (line.length() - offset) : length); + return line.mid(offset, length == -1 ? (line.length() - offset) : length); } ParserPrivate::ParserPrivate(Parser* parser, QIODevice* file, FileData* data, @@ -186,7 +186,7 @@ void ParserPrivate::parseFileTimeUnit(const QByteArray& line) void ParserPrivate::parseSnapshot(const QByteArray& line) { - VALIDATE(line, line == "#-----------") + VALIDATE(line, line.startsWith("#-----------")) // snapshot=N QByteArray nextLine = readLine(); @@ -195,7 +195,7 @@ void ParserPrivate::parseSnapshot(const QByteArray& line) uint number = midRef(nextLine, 9).toUInt(&ok); VALIDATE(nextLine, ok) nextLine = readLine(); - VALIDATE(nextLine, nextLine == "#-----------") + VALIDATE(nextLine, nextLine.startsWith("#-----------")) m_snapshot = new SnapshotItem; m_data->addSnapshot(m_snapshot);