fix code check warning

Signed-off-by: liduo <liduo29@huawei.com>
This commit is contained in:
liduo
2024-11-15 14:20:58 +08:00
parent 806bf302e4
commit 3efb2a5786
3 changed files with 15 additions and 0 deletions
+3
View File
@@ -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;
+4
View File
@@ -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;
}
+8
View File
@@ -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<const char *>(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<const char *>(resourceItem.GetData()), resourceItem.GetDataLength());
vector<string> contents = ResourceUtil::DecomposeStrings(data);
if (contents.empty()) {