!137 cppcheck告警修改

Merge pull request !137 from fyz1019/master
This commit is contained in:
openharmony_ci
2024-03-11 13:58:21 +00:00
committed by Gitee
5 changed files with 16 additions and 27 deletions
-1
View File
@@ -49,7 +49,6 @@ ohos_executable("restool") {
include_dirs = [
"include",
"//third_party/jsoncpp/include",
"//third_party/bounds_checking_function/include",
]
+6 -10
View File
@@ -72,20 +72,16 @@ uint32_t FileManager::ParseReference(const string &output)
void FileManager::CheckAllItems(vector<pair<ResType, string>> &noBaseResource)
{
for (const auto &item : items_) {
bool flag = false;
for (const auto &iter : item.second) {
if (iter.GetLimitKey() == "base") {
flag = true;
break;
}
}
if (!flag) {
bool found = any_of(item.second.begin(), item.second.end(), [](const auto &iter) {
return iter.GetLimitKey() == "base";
});
if (!found) {
auto firstItem = item.second.front();
auto ret = find_if(noBaseResource.begin(), noBaseResource.end(), [firstItem](auto &iterItem) {
bool ret = any_of(noBaseResource.begin(), noBaseResource.end(), [firstItem](const auto &iterItem) {
return (firstItem.GetResType() == iterItem.first) &&
(firstItem.GetName() == iterItem.second);
});
if (ret == noBaseResource.end()) {
if (!ret) {
noBaseResource.push_back(make_pair(firstItem.GetResType(), firstItem.GetName()));
}
}
+6 -10
View File
@@ -679,20 +679,16 @@ bool ResourceAppend::IsBaseIdDefined(const FileInfo &fileInfo)
void ResourceAppend::CheckAllItems(vector<pair<ResType, string>> &noBaseResource)
{
for (const auto &item : items_) {
bool flag = false;
for (const auto &iter : item.second) {
if (iter->GetLimitKey() == "base") {
flag = true;
break;
}
}
if (!flag) {
bool found = any_of(item.second.begin(), item.second.end(), [](const auto &iter) {
return iter->GetLimitKey() == "base";
});
if (!found) {
auto firstItem = item.second.front();
auto ret = find_if(noBaseResource.begin(), noBaseResource.end(), [firstItem](auto &iterItem) {
bool ret = any_of(noBaseResource.begin(), noBaseResource.end(), [firstItem](const auto &iterItem) {
return (firstItem->GetResType() == iterItem.first) &&
(firstItem->GetName() == iterItem.second);
});
if (ret == noBaseResource.end()) {
if (!ret) {
noBaseResource.push_back(make_pair(firstItem->GetResType(), firstItem->GetName()));
}
}
+2 -2
View File
@@ -80,8 +80,8 @@ bool ResourceUtil::OpenJsonFile(const string &path, cJSON **root)
string jsonString((istreambuf_iterator<char>(ifs)), istreambuf_iterator<char>());
*root = cJSON_Parse(jsonString.c_str());
if (!root) {
cerr << "Error: cJSON_Parse failed." << NEW_LINE_PATH << path;
if (!*root) {
cerr << "Error: cJSON_Parse failed, please check the JSON file." << NEW_LINE_PATH << path;
cerr << "\n" << cJSON_GetErrorPtr() << endl;
ifs.close();
return false;
+2 -4
View File
@@ -116,7 +116,7 @@ bool TranslatableParse::CheckBaseStringPriority(const cJSON *attrNode)
string priorityValue = priorityNode->valuestring;
if (find(PRIORITY_ATTRS.begin(), PRIORITY_ATTRS.end(), priorityValue) == PRIORITY_ATTRS.end()) {
string message("[ ");
for (auto &value : PRIORITY_ATTRS) {
for (const auto &value : PRIORITY_ATTRS) {
message.append("'" + value + "' ");
}
message.append("]");
@@ -148,11 +148,9 @@ bool TranslatableParse::GetReplaceStringTranslate(string &str)
return false;
}
size_t startIndex = 0;
size_t endIndex = 0;
string tmp;
for (size_t index = 0; index < posData.size(); index++) {
endIndex = posData[index];
tmp.append(str, startIndex, endIndex - startIndex);
tmp.append(str, startIndex, posData[index] - startIndex);
startIndex = posData[++index];
}
str = tmp.append(str, posData.back());