From 3efb2a5786fd285c5464db3feaf695b944e7a7a4 Mon Sep 17 00:00:00 2001 From: liduo Date: Fri, 15 Nov 2024 14:20:58 +0800 Subject: [PATCH] fix code check warning Signed-off-by: liduo --- src/compression_parser.cpp | 3 +++ src/id_defined_parser.cpp | 4 ++++ src/reference_parser.cpp | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/src/compression_parser.cpp b/src/compression_parser.cpp index 9dd3bf0..5b33012 100644 --- a/src/compression_parser.cpp +++ b/src/compression_parser.cpp @@ -292,6 +292,9 @@ string CompressionParser::ParseJsonStr(const cJSON *node) return ""; } char *jsonString = cJSON_Print(node); + if (jsonString == nullptr) { + return ""; + } string res(jsonString); free(jsonString); return res; diff --git a/src/id_defined_parser.cpp b/src/id_defined_parser.cpp index bb34e16..381b639 100755 --- a/src/id_defined_parser.cpp +++ b/src/id_defined_parser.cpp @@ -291,6 +291,10 @@ int64_t IdDefinedParser::GetStartId() const } int64_t id = strtoll(startIdNode->valuestring, nullptr, 16); + if (id == 0) { + cerr << "Error: id_defined.json 'startId' is not a valid hexadecimal string." << endl; + return -1; + } return id; } diff --git a/src/reference_parser.cpp b/src/reference_parser.cpp index cea1d96..2cb8ed2 100644 --- a/src/reference_parser.cpp +++ b/src/reference_parser.cpp @@ -88,6 +88,10 @@ uint32_t ReferenceParser::ParseRefInResourceItem(ResourceItem &resourceItem) con string data; bool update = false; if (IsStringOfResourceItem(resType)) { + if (resourceItem.GetData() == nullptr) { + cerr << "Error: parse ref in resource item failed, data is null." << endl; + return RESTOOL_ERROR; + } data = string(reinterpret_cast(resourceItem.GetData()), resourceItem.GetDataLength()); if (!ParseRefString(data, update)) { cerr << "Error: please check JSON file." << NEW_LINE_PATH << resourceItem.GetFilePath() << endl; @@ -182,6 +186,10 @@ bool ReferenceParser::ParseRefJson(const string &from, const string &to) bool ReferenceParser::ParseRefResourceItemData(const ResourceItem &resourceItem, string &data, bool &update) const { + if (resourceItem.GetData() == nullptr) { + cerr << "Error: parse ref resource item data failed, data is null." << endl; + return false; + } data = string(reinterpret_cast(resourceItem.GetData()), resourceItem.GetDataLength()); vector contents = ResourceUtil::DecomposeStrings(data); if (contents.empty()) {