diff --git a/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c b/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c index aac4de154c5f1a1cdc75da2c00e18bab679c10ce..802ceaee667fbe3f0446888ffe2d5e9a1013b637 100644 --- a/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c +++ b/interfaces/innerkits/nativetoken/src/nativetoken_json_oper.c @@ -83,7 +83,7 @@ uint32_t GetInfoArrFromJson(cJSON *cjsonItem, char *strArr[], int32_t *strNum, S } *strNum = size; - for (int32_t i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { cJSON *item = cJSON_GetArrayItem(strArrJson, i); if ((item == NULL) || (!cJSON_IsString(item)) || (item->valuestring == NULL)) { AT_LOG_ERROR("[ATLIB-%s]:cJSON_GetArrayItem failed.", __func__); diff --git a/interfaces/innerkits/nativetoken/test/unittest/src/nativetoken_kit_test.cpp b/interfaces/innerkits/nativetoken/test/unittest/src/nativetoken_kit_test.cpp index 225bac7eb4f5d097519501d2fa6c41ce525432d4..df7db9eca56958498f610d83baf8385de6a1a22e 100644 --- a/interfaces/innerkits/nativetoken/test/unittest/src/nativetoken_kit_test.cpp +++ b/interfaces/innerkits/nativetoken/test/unittest/src/nativetoken_kit_test.cpp @@ -680,7 +680,7 @@ HWTEST_F(TokenLibKitTest, GetAccessTokenId014, TestSize.Level0) */ HWTEST_F(TokenLibKitTest, GetAccessTokenId015, TestSize.Level1) { - const char **perms = new const char *[MAX_PERM_NUM]; + const char **perms = new const char *[MAX_PERM_NUM + 1]; perms[0] = "ohos.permission.test1"; perms[1] = "ohos.permission.test2"; int32_t permsNum = 2; @@ -699,16 +699,16 @@ HWTEST_F(TokenLibKitTest, GetAccessTokenId015, TestSize.Level1) tokenId = GetAccessTokenId(&infoInstance); ASSERT_EQ(tokenId, 0); + for (int32_t i = 0; i < MAX_PERM_NUM + 1; i++) { + perms[i] = "ohos.permission.test"; + } + infoInstance.permsNum = MAX_PERM_NUM; infoInstance.aclsNum = MAX_PERM_NUM + 1; infoInstance.processName = "GetAccessTokenId015_00"; tokenId = GetAccessTokenId(&infoInstance); ASSERT_EQ(tokenId, 0); - for (int32_t i = 0; i < MAX_PERM_NUM; i++) { - perms[i] = "ohos.permission.test"; - } - permsNum = MAX_PERM_NUM; infoInstance.permsNum = permsNum; infoInstance.aclsNum = permsNum;