替换atoi函数

Signed-off-by: swg3156201044 <shiweigang2@huawei.com>
This commit is contained in:
swg3156201044 2024-09-18 12:55:51 +00:00
parent adfdb7d7d5
commit 0dc6480aa3
3 changed files with 33 additions and 13 deletions

View File

@ -19,6 +19,7 @@
#include "account_log_wrapper.h"
#include "nlohmann/json.hpp"
#include "securec.h"
#include "string_ex.h"
namespace OHOS {
namespace AccountSA {
@ -524,7 +525,12 @@ bool BundleManagerAdapterProxy::GetParcelableFromAshmem(MessageParcel &reply, T
return false;
}
int strLen = atoi(lenStr.c_str());
int32_t strLen = 0;
if (!StrToInt(lenStr, strLen)) {
ACCOUNT_LOGE("Convert lenStr failed");
ClearAshmem(ashmem);
return false;
}
offset += ASHMEM_LEN;
std::string infoStr;
if (!ParseStr(dataStr, strLen, offset, infoStr)) {
@ -648,7 +654,11 @@ bool BundleManagerAdapterProxy::ParseAshmem(
if (!ParseStr(dataStr, ASHMEM_LEN, offset, lenStr)) {
return false;
}
int strLen = atoi(lenStr.c_str());
int32_t strLen = 0;
if (!StrToInt(lenStr, strLen)) {
ACCOUNT_LOGE("Convert lenStr failed");
return false;
}
offset += ASHMEM_LEN;
std::string infoStr;
if (!ParseStr(dataStr, strLen, offset, infoStr)) {

View File

@ -27,6 +27,7 @@
#ifdef HAS_CONFIG_POLICY_PART
#include "config_policy_utils.h"
#endif
#include "string_ex.h"
#include "os_account_constants.h"
#include "os_account_interface.h"
@ -263,7 +264,12 @@ void OsAccountControlFileManager::Init()
accountListJson, jsonEnd, Constants::ACCOUNT_LIST, accountIdList, OHOS::AccountSA::JsonType::ARRAY);
if (!accountIdList.empty()) {
std::lock_guard<std::mutex> lock(operatingIdMutex_);
nextLocalId_ = atoi(accountIdList[accountIdList.size() - 1].c_str()) + 1;
int32_t id = 0;
if (!StrToInt(accountIdList[accountIdList.size() - 1], id)) {
ACCOUNT_LOGE("Convert localId failed");
return;
}
nextLocalId_ = id + 1;
InitFileWatcherInfo(accountIdList);
}
ACCOUNT_LOGI("OsAccountControlFileManager Init end");
@ -454,7 +460,12 @@ ErrCode OsAccountControlFileManager::GetOsAccountIdList(std::vector<int32_t> &id
OHOS::AccountSA::GetDataByType<std::vector<std::string>>(accountListJson, accountListJson.end(),
Constants::ACCOUNT_LIST, idStrList, OHOS::AccountSA::JsonType::ARRAY);
for (const auto &idStr : idStrList) {
idList.emplace_back(atoi(idStr.c_str()));
int32_t id = 0;
if (!StrToInt(idStr, id)) {
ACCOUNT_LOGE("Convert localId failed");
continue;
}
idList.emplace_back(id);
}
return errCode;
}
@ -483,7 +494,12 @@ ErrCode OsAccountControlFileManager::GetOsAccountList(std::vector<OsAccountInfo>
for (const auto& it : idList) {
OsAccountInfo osAccountInfo;
if (GetOsAccountInfoById(std::atoi(it.c_str()), osAccountInfo) == ERR_OK) {
int32_t id = 0;
if (!StrToInt(it, id)) {
ACCOUNT_LOGE("Convert localId failed");
continue;
}
if (GetOsAccountInfoById(id, osAccountInfo) == ERR_OK) {
if (osAccountInfo.GetPhoto() != "") {
std::string photo = osAccountInfo.GetPhoto();
GetPhotoById(osAccountInfo.GetLocalId(), photo);

View File

@ -18,6 +18,7 @@
#include <sys/stat.h>
#include "account_log_wrapper.h"
#include "singleton.h"
#include "string_ex.h"
using namespace OHOS::AAFwk;
@ -731,18 +732,11 @@ ErrCode AccountCommand::AnalyzeDisallowedListArgument(std::vector<std::string> &
ErrCode AccountCommand::AnalyzeLocalIdArgument(int &id)
{
std::string idByUser = optarg;
if (idByUser == "0") {
id = 0;
return ERR_OK;
}
if (atoi(optarg) == 0) {
if (!StrToInt(idByUser, id)) {
resultReceiver_.append(HELP_MSG_INVALID_ID_ARGUMENT + "\n");
return ERR_INVALID_VALUE;
}
id = atoi(optarg);
return ERR_OK;
}