diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index f5a53ad91aa1712ad6f32fa4c4a8e49e80eee505..3e2f82d64dae51cf5b8e6019904f414f02076056 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -451,7 +451,7 @@ char *DecodeRpcidToStringFormat(char *inputFile) // malloc for save private syscap string priSyscapArray = (char *)malloc(sysCapArraySize * SINGLE_FEAT_LENGTH); if (priSyscapArray == NULL) { - PRINT_ERR("malloc(%u) failed.\n", sysCapArraySize * SINGLE_FEAT_LENGTH); + PRINT_ERR("malloc(%u) failed.\n", (uint32_t)sysCapArraySize * SINGLE_FEAT_LENGTH); goto FREE_MALLOC_OSSYSCAP; } (void)memset_s(priSyscapArray, sysCapArraySize * SINGLE_FEAT_LENGTH, @@ -462,7 +462,7 @@ char *DecodeRpcidToStringFormat(char *inputFile) cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, i); cJsonTemp = cJSON_GetObjectItem(sysCapDefine, cJsonItem->valuestring); if (cJsonTemp != NULL) { - osSysCapIndex[indexOs++] = cJsonTemp->valueint; + osSysCapIndex[indexOs++] = (uint16_t)(cJsonTemp->valueint); } else { ret = strncpy_s(priSyscapArray, sysCapArraySize * SINGLE_FEAT_LENGTH, cJsonItem->valuestring, SINGLE_FEAT_LENGTH - 1); @@ -483,8 +483,8 @@ char *DecodeRpcidToStringFormat(char *inputFile) goto FREE_MALLOC_PRISYSCAP; } - uint16_t outBufferLen = U32_TO_STR_MAX_LEN * RPCID_OUT_BUFFER - + (SINGLE_FEAT_LENGTH + 1) * sysCapArraySize; + uint32_t outBufferLen = U32_TO_STR_MAX_LEN * RPCID_OUT_BUFFER + + (SINGLE_FEAT_LENGTH + 1) * (uint32_t)sysCapArraySize; outBuffer = (char *)malloc(outBufferLen); if (outBuffer == NULL) { PRINT_ERR("malloc(%u) failed.\n", outBufferLen); diff --git a/src/main.c b/src/main.c index 964efa940805a928ba19e7025de51104dfc43c93..09453b4066d85f49236a4e1b79a62ba1905777fc 100644 --- a/src/main.c +++ b/src/main.c @@ -80,8 +80,8 @@ int main(int argc, char **argv) break; case 'C': pcidfile = optarg; - if (optind < 0 || optind > argc) { - PRINT_ERR("Input file path too few or too many.\n"); + if (argc != 4 || optind < 0 || optind >= argc) { // 4, argc of ./syscap_tool -C f1 f2 + PRINT_ERR("Input file too few or too many.\n"); return -1; } rpcidfile = argv[optind]; diff --git a/src/syscap_tool.c b/src/syscap_tool.c index c2cb265d8ef87c9a86fea00c90c0f8d363c7fd17..385ebc5c0e0940f4ebc778695a41eedf43751218 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -479,7 +479,7 @@ int32_t DecodeRpcidToString(char *inputFile, char *outDirPath) // malloc for save private syscap string priSyscapArray = (char *)malloc(sysCapArraySize * SINGLE_FEAT_LENGTH); if (priSyscapArray == NULL) { - PRINT_ERR("malloc(%u) failed.\n", sysCapArraySize * SINGLE_FEAT_LENGTH); + PRINT_ERR("malloc(%d) failed.\n", sysCapArraySize * SINGLE_FEAT_LENGTH); goto FREE_MALLOC_OSSYSCAP; } (void)memset_s(priSyscapArray, sysCapArraySize * SINGLE_FEAT_LENGTH, diff --git a/test/unittest/common/syscap_codec_test.cpp b/test/unittest/common/syscap_codec_test.cpp index 829ca2f6d1e51fe92964b634851cb513fef8d9fb..354f4d571c54420fc3d52d3625dbe3579a2deac1 100644 --- a/test/unittest/common/syscap_codec_test.cpp +++ b/test/unittest/common/syscap_codec_test.cpp @@ -100,22 +100,6 @@ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1) free(priOutput); } -/* - * @tc.name: DecodeRpcidToStringFormat - * @tc.desc: Check the DecodeRpcidToStringFormat Decoding. - * @tc.type: FUNC - */ -HWTEST_F(SyscapCodecTest, DecodeRpcidToStringFormat, TestSize.Level1) -{ - char inputfile[] = "/system/etc/rpcid.sc"; - char *out = DecodeRpcidToStringFormat(inputfile); - EXPECT_TRUE(out); - if (out != NULL) { - printf("%s\n", out); - free(out); - } -} - /* * @tc.name: ComparePcidString * @tc.desc: Check the DecodeRpcidToStringFormat Decoding.