fix: fix string exception

Signed-off-by: liujiandong <liujiandong1@huawei.com>
This commit is contained in:
YOUR_NAME 2024-02-01 16:17:28 +08:00
parent b5c04c1bf8
commit 61e779cbc8
2 changed files with 9 additions and 1 deletions

View File

@ -519,7 +519,13 @@ std::string IccFile::ObtainValidLanguage(const std::string &langData)
TELEPHONY_LOGE("data is nullptr!!");
return "";
}
TELEPHONY_LOGI("ObtainValidLanguage all is %{public}s---%{public}d", data, langDataLen);
int dataLen = static_cast<int>(strlen(reinterpret_cast<char *>(data)));
TELEPHONY_LOGI("ObtainValidLanguage all is %{public}s---%{public}d, dataLen:%{public}d",
data, langDataLen, dataLen);
if (langDataLen > dataLen) {
langDataLen = dataLen;
}
for (int i = 0; (i + 1) < langDataLen; i += DATA_STEP) {
std::string langName((char *)data, i, DATA_STEP);
TELEPHONY_LOGI("ObtainValidLanguage item is %{public}d--%{public}s", i, langName.c_str());

View File

@ -2801,6 +2801,8 @@ HWTEST_F(BranchTest, Telephony_IccFile_002, Function | MediumTest | Level1) {
EXPECT_EQ(iccId, "2143BA65FT");
std::string langData = "";
EXPECT_EQ(iccFile->ObtainValidLanguage(langData), "");
langData = "000011286F050400000000010203FF";
EXPECT_EQ(iccFile->ObtainValidLanguage(langData), "");
}
/**