CTF: Use QT_FSTAT to read file size

Pick-to: 6.5
Change-Id: Ic4b184e1ed51d8e30c2305a5ead619117a505518
Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
This commit is contained in:
Antti Määttä 2023-05-29 09:12:46 +03:00
parent 5e2b4c401d
commit dad95f4a43

View File

@ -75,13 +75,16 @@ QCtfLibImpl::QCtfLibImpl()
m_session.tracepoints.append(QStringLiteral("all"));
m_session.name = QStringLiteral("default");
} else {
fseek(file, 0, SEEK_END);
qsizetype pos = ftell(file);
fseek(file, 0, SEEK_SET);
QByteArray data(pos, Qt::Uninitialized);
qsizetype size = (qsizetype)fread(data.data(), 1, pos, file);
QT_STATBUF stat;
if (QT_FSTAT(QT_FILENO(file), &stat) != 0) {
qCWarning (lcDebugTrace) << "Unable to stat session file, " << qt_error_string();
return;
}
qsizetype filesize = qMin(stat.st_size, std::numeric_limits<qsizetype>::max());
QByteArray data(filesize, Qt::Uninitialized);
qsizetype size = static_cast<qsizetype>(fread(data.data(), 1, filesize, file));
fclose(file);
if (size != pos)
if (size != filesize)
return;
QJsonDocument json(QJsonDocument::fromJson(data));