CTF: Properly handle invalid session file
Pick-to: 6.5 Change-Id: Iabb2621364b5256ac89ec8cb7fafb0a9d346515d Reviewed-by: Antti Määttä <antti.maatta@qt.io> Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
This commit is contained in:
parent
6639285ad7
commit
d214c56e43
@ -87,17 +87,24 @@ QCtfLibImpl::QCtfLibImpl()
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
if (size != filesize)
|
if (size != filesize)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QJsonDocument json(QJsonDocument::fromJson(data));
|
QJsonDocument json(QJsonDocument::fromJson(data));
|
||||||
|
|
||||||
QJsonObject obj = json.object();
|
QJsonObject obj = json.object();
|
||||||
QJsonValue value = *obj.begin();
|
bool valid = false;
|
||||||
if (value.isNull() || !value.isArray())
|
if (!obj.isEmpty()) {
|
||||||
return;
|
const auto it = obj.begin();
|
||||||
m_session.name = obj.begin().key();
|
if (it.value().isArray()) {
|
||||||
const QJsonArray arr = value.toArray();
|
m_session.name = it.key();
|
||||||
for (auto var : arr)
|
for (auto var : it.value().toArray())
|
||||||
m_session.tracepoints.append(var.toString());
|
m_session.tracepoints.append(var.toString());
|
||||||
|
valid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
|
qCWarning(lcDebugTrace) << "Session file is not valid";
|
||||||
|
m_session.tracepoints.append(QStringLiteral("all"));
|
||||||
|
m_session.name = QStringLiteral("default");
|
||||||
|
}
|
||||||
m_location = location + QStringLiteral("/ust");
|
m_location = location + QStringLiteral("/ust");
|
||||||
std::filesystem::create_directory(qPrintable(m_location), qPrintable(location));
|
std::filesystem::create_directory(qPrintable(m_location), qPrintable(location));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user