Limit amount of JSON dumped in case of error. (#2081)

This commit is contained in:
karliss 2020-03-04 09:39:52 +02:00 committed by GitHub
parent 58d9e52662
commit b173d05865
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -445,7 +445,14 @@ QJsonDocument CutterCore::parseJson(const char *res, const char *cmd)
} else {
eprintf("Failed to parse JSON: %s\n", jsonError.errorString().toLocal8Bit().constData());
}
eprintf("%s\n", json.constData());
const int MAX_JSON_DUMP_SIZE = 8 * 1024;
if (json.length() > MAX_JSON_DUMP_SIZE) {
int originalSize = json.length();
json.resize(MAX_JSON_DUMP_SIZE);
eprintf("%d bytes total: %s ...\n", originalSize, json.constData());
} else {
eprintf("%s\n", json.constData());
}
}
return doc;