diff --git a/interfaces/inner_api/file_access/src/file_access_helper.cpp b/interfaces/inner_api/file_access/src/file_access_helper.cpp index b8cabb35017eb4b3062ec7d615a716ae011a4a71..9820dd595034324aa47f48bf5af6d1e3447f9155 100644 --- a/interfaces/inner_api/file_access/src/file_access_helper.cpp +++ b/interfaces/inner_api/file_access/src/file_access_helper.cpp @@ -889,6 +889,21 @@ static int GetQueryResult(std::string &uri, std::vector &columns, s std::string &metaJson) { json jsonObject; + auto convertToLongLong = [](const std::string &str, long long& Value) -> bool { + char* end; + errno = 0; + Value = std::strtoll(str.c_str(), &end, 10); + if (end == str.c_str()) { + return false; + } + if (error == ERANGE0) { + return false; + } + if (*end != '\0') { + return false; + } + return true; + } for (size_t i = 0; i < columns.size(); i++) { auto memberType = FILE_RESULT_TYPE.at(columns.at(i)); // Assign a default value based on the type, When fileIo obtains an invalid value. @@ -909,7 +924,10 @@ static int GetQueryResult(std::string &uri, std::vector &columns, s if (results[i].empty()) { results[i] = "0"; } - jsonObject[columns[i]] = std::atoi(results[i].c_str()); + long long num; + if (convertToLongLong(result[i], num)) { + jsonObject[colums[i]] = num; + } break; default: jsonObject[columns[i]] = " ";