From c630e9939fe380a3b93cb5980db68452a564b8bc Mon Sep 17 00:00:00 2001 From: yudechen Date: Tue, 12 Jul 2022 11:15:25 +0800 Subject: [PATCH 1/5] fixed 6082616 from https://gitee.com/yudechen/developtools_syscap_codec/pulls/88 change global variable arraySyscap to g_arraySyscap. Signed-off-by: yudechen Change-Id: Ia723dfc0bb1d78500e57ae823f33978c81ebd36b --- include/syscap_define.h | 4 ++-- interfaces/inner_api/syscap_interface.c | 12 ++++++------ src/create_pcid.c | 20 ++++++++++---------- src/syscap_tool.c | 6 +++--- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/syscap_define.h b/include/syscap_define.h index 4d28c17..9e1c899 100644 --- a/include/syscap_define.h +++ b/include/syscap_define.h @@ -21,7 +21,7 @@ #define SINGLE_SYSCAP_LEN (256 + 17) typedef struct SystemCapabilityWithNum { - char syscapStr[SINGLE_SYSCAP_LEN]; + char str[SINGLE_SYSCAP_LEN]; uint16_t num; } SyscapWithNum; @@ -181,7 +181,7 @@ typedef enum SystemCapabilityNum { } SyscapNum; /* sort by enum */ -const static SyscapWithNum arraySyscap[] = { +const static SyscapWithNum g_arraySyscap[] = { {"SystemCapability.Account.AppAccount", ACCOUNT_APPACCOUNT}, {"SystemCapability.Account.OsAccount", ACCOUNT_OSACCOUNT}, {"SystemCapability.Ace.UiAppearance", ACE_UIAPPEARANCE}, diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 0e2ece2..2cb0357 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -219,9 +219,9 @@ bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SY *output = strSyscap; for (i = 0; i < countOfSyscap; i++) { - for (j = 0; j < sizeof(arraySyscap) / sizeof(SyscapWithNum); j++) { - if (arraySyscap[j].num == indexOfSyscap[i]) { - nRet = strcpy_s(*strSyscap, SINGLE_SYSCAP_LEN, arraySyscap[j].syscapStr); + for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { + if (g_arraySyscap[j].num == indexOfSyscap[i]) { + nRet = strcpy_s(*strSyscap, SINGLE_SYSCAP_LEN, g_arraySyscap[j].str); if (nRet != EOK) { printf("strcpy_s failed. error = %d\n", nRet); *outputCnt = 0; @@ -322,10 +322,10 @@ static int SetOsSysCapBitMap(uint8_t *out, uint16_t outLen, uint16_t *index, uin static cJSON *CreateWholeSyscapJsonObj(void) { - size_t numOfSyscapAll = sizeof(arraySyscap) / sizeof(SyscapWithNum); + size_t numOfSyscapAll = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); cJSON *root = cJSON_CreateObject(); for (size_t i = 0; i < numOfSyscapAll; i++) { - cJSON_AddItemToObject(root, arraySyscap[i].syscapStr, cJSON_CreateNumber(arraySyscap[i].num)); + cJSON_AddItemToObject(root, g_arraySyscap[i].str, cJSON_CreateNumber(g_arraySyscap[i].num)); } return root; } @@ -591,7 +591,7 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa return -1; } ret = strcpy_s(temp, sizeof(char) * SINGLE_SYSCAP_LEN, - arraySyscap[(i - 2) * INT_BIT + k].syscapStr); // 2, header of pcid & rpcid + g_arraySyscap[(i - 2) * INT_BIT + k].str); // 2, header of pcid & rpcid if (ret != EOK) { PRINT_ERR("strcpy_s failed.\n"); FreeCompareError(result); diff --git a/src/create_pcid.c b/src/create_pcid.c index af2b2ce..8710a95 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -158,10 +158,10 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename static cJSON *CreateWholeSyscapJsonObj(void) { - size_t numOfSyscapAll = sizeof(arraySyscap) / sizeof(SyscapWithNum); + size_t numOfSyscapAll = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); cJSON *root = cJSON_CreateObject(); for (size_t i = 0; i < numOfSyscapAll; i++) { - cJSON_AddItemToObject(root, arraySyscap[i].syscapStr, cJSON_CreateNumber(arraySyscap[i].num)); + cJSON_AddItemToObject(root, g_arraySyscap[i].str, cJSON_CreateNumber(g_arraySyscap[i].num)); } return root; } @@ -393,9 +393,9 @@ int32_t DecodePCID(char *inputFile, char *outDirPath) } } for (i = 0; i < countOfSyscap; i++) { - for (j = 0; j < sizeof(arraySyscap) / sizeof(SyscapWithNum); j++) { - if (arraySyscap[j].num == indexOfSyscap[i]) { - if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(arraySyscap[j].syscapStr))) { + for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { + if (g_arraySyscap[j].num == indexOfSyscap[i]) { + if (!cJSON_AddItemToArray(capVectorPtr, cJSON_CreateString(g_arraySyscap[j].str))) { printf("cJSON_AddItemToArray or cJSON_CreateString failed\n"); ret = -1; goto FREE_VECTOR_OUT; @@ -614,11 +614,11 @@ static int32_t AddOsSyscapToJsonObj(uint32_t *osSyscapArray, uint32_t osSyscapAr } for (i = 0; i < osSyscapCount; i++) { - for (j = 0; j < sizeof(arraySyscap) / sizeof(SyscapWithNum); j++) { - if (index[i] != arraySyscap[j].num) { + for (j = 0; j < sizeof(g_arraySyscap) / sizeof(SyscapWithNum); j++) { + if (index[i] != g_arraySyscap[j].num) { continue; } - if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(arraySyscap[j].syscapStr))) { + if (!cJSON_AddItemToArray(sysCapArray, cJSON_CreateString(g_arraySyscap[j].str))) { PRINT_ERR("Add os syscap string to json failed.\n"); free(sysCapArray); return -1; @@ -732,8 +732,8 @@ PARSE_FAILED: int32_t EncodePcidscToString(char *inputFile, char *outDirPath) { int32_t ret = 0; - size_t bufferLen, privateSyscapLen; - uint32_t i, j, outputLen; + size_t bufferLen, privateSyscapLen, outputLen; + uint32_t i, j; uint32_t *mainSyscap = NULL; uint16_t priSyscapCount = 0; char *contextBuffer = NULL; diff --git a/src/syscap_tool.c b/src/syscap_tool.c index d5cceca..81b7190 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -174,10 +174,10 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename static cJSON *CreateWholeSyscapJsonObj(void) { - size_t numOfSyscapAll = sizeof(arraySyscap) / sizeof(SyscapWithNum); + size_t numOfSyscapAll = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); cJSON *root = cJSON_CreateObject(); for (size_t i = 0; i < numOfSyscapAll; i++) { - cJSON_AddItemToObject(root, arraySyscap[i].syscapStr, cJSON_CreateNumber(arraySyscap[i].num)); + cJSON_AddItemToObject(root, g_arraySyscap[i].str, cJSON_CreateNumber(g_arraySyscap[i].num)); } return root; } @@ -699,7 +699,7 @@ int32_t ComparePcidWithRpcidString(char *pcidFile, char *rpcidFile) for (uint8_t k = 0; k < INT_BIT; k++) { if (temp2 & (0x1 << k)) { // 2, header of pcid & rpcid - printf("Missing: %s\n", arraySyscap[(i - 2) * INT_BIT + k].syscapStr); + printf("Missing: %s\n", g_arraySyscap[(i - 2) * INT_BIT + k].str); ossyscapFlag += 1; } } -- Gitee From 8b3f32d6987345c4a2154a2d4109fff7fd8eee66 Mon Sep 17 00:00:00 2001 From: yudechen Date: Mon, 11 Jul 2022 18:49:50 +0800 Subject: [PATCH 2/5] fixed 83673dd from https://gitee.com/yudechen/developtools_syscap_codec/pulls/88 signed type cannot be involved in the bit operation. Signed-off-by: yudechen Change-Id: Ie5bd5a9983348cd469b7cc72bc24549927feaa9b --- interfaces/inner_api/syscap_interface.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 2cb0357..2adeb39 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -556,6 +556,7 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa bool priSysFound; uint32_t pcidPriSyscapLen, rpcidPriSyscapLen; uint32_t i, j, temp1, temp2; + uint32_t retFlag = 0; uint32_t pcidOsAarry[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; @@ -632,13 +633,13 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa } if (versionFlag > 0) { - ret |= 0x1 << 0; + retFlag |= 0x1 << 0; } if (ossyscapFlag > 0 || prisyscapFlag > 0) { - ret |= 0x1 << 1; + retFlag |= 0x1 << 1; result->missSyscapNum = ossyscapFlag + prisyscapFlag; } - return ret; + return retFlag; } int32_t FreeCompareError(CompareError *result) -- Gitee From 8ecbdb1373b681a6819519ea6f58321f44348b2e Mon Sep 17 00:00:00 2001 From: yudechen Date: Mon, 11 Jul 2022 18:38:24 +0800 Subject: [PATCH 3/5] fixed 898ed7d from https://gitee.com/yudechen/developtools_syscap_codec/pulls/88 modify for coding style. Signed-off-by: yudechen Change-Id: I741db340849990f6925020f894b7ac148ac94e46 --- interfaces/inner_api/syscap_interface.c | 4 ++-- src/syscap_tool.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 2adeb39..db288e7 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -378,7 +378,7 @@ FREE_SYSCAP_OUT: return ret; } -static int32_t CheckRpcidFormat(const char *inputFile, char **buffer, uint32_t *Len) +static int32_t CheckRpcidFormat(const char *inputFile, char **buffer, uint32_t *len) { uint32_t bufferLen; uint16_t sysCaptype, sysCapLength; @@ -410,7 +410,7 @@ static int32_t CheckRpcidFormat(const char *inputFile, char **buffer, uint32_t * } *buffer = contextBuffer; - *Len = bufferLen; + *len = bufferLen; return 0; } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 81b7190..54c7063 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -569,7 +569,7 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin { int32_t ret = 0; uint32_t i; - uint32_t inputLen = strlen(inputString); + size_t inputLen = strlen(inputString); uint32_t count = 0; char *temp = NULL; char *tok = NULL; -- Gitee From 8ac0143bcb6d8864358c116ae51c40d6594d6403 Mon Sep 17 00:00:00 2001 From: yudechen Date: Thu, 14 Jul 2022 09:13:34 +0800 Subject: [PATCH 4/5] fixed 87e6fb0 from https://gitee.com/yudechen/developtools_syscap_codec/pulls/90 fix data type conversion problem. Signed-off-by: yudechen Change-Id: I4bbb49df814f6d791d0d3eed7933005c0ab0ba51 --- interfaces/inner_api/syscap_interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index db288e7..a42a7a5 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -639,7 +639,7 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa retFlag |= 0x1 << 1; result->missSyscapNum = ossyscapFlag + prisyscapFlag; } - return retFlag; + return (int32_t)retFlag; } int32_t FreeCompareError(CompareError *result) -- Gitee From ff355e4d822b7a249a30c390a7fd692df8b8f69a Mon Sep 17 00:00:00 2001 From: yudechen Date: Mon, 25 Jul 2022 19:27:37 +0800 Subject: [PATCH 5/5] chore: remove some useless headfer file. Signed-off-by: yudechen Change-Id: Ic3ed32011690f639ebe2062701a0b73a5eee5270 --- include/syscap_tool.h | 2 +- interfaces/inner_api/syscap_interface.c | 4 +--- napi/napi_query_syscap.cpp | 5 ++--- src/create_pcid.c | 4 ---- src/endian_internal.c | 1 - src/syscap_tool.c | 4 ---- .../unittest/common/include/syscap_codec_test.h | 2 -- test/unittest/common/syscap_codec_test.cpp | 17 +++++++++-------- 8 files changed, 13 insertions(+), 26 deletions(-) diff --git a/include/syscap_tool.h b/include/syscap_tool.h index 8ec1899..d485c9b 100644 --- a/include/syscap_tool.h +++ b/include/syscap_tool.h @@ -16,7 +16,7 @@ #ifndef _SYSCAP_TOOL_H #define _SYSCAP_TOOL_H -#include "stdint.h" +#include #define TYPE_FILE (0U) #define TYPE_STRING (1U) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index a42a7a5..14082ca 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -13,10 +13,8 @@ * limitations under the License. */ +#include #include -#include -#include -#include #include #include #include diff --git a/napi/napi_query_syscap.cpp b/napi/napi_query_syscap.cpp index 09dc080..5cbb3d9 100644 --- a/napi/napi_query_syscap.cpp +++ b/napi/napi_query_syscap.cpp @@ -13,11 +13,10 @@ * limitations under the License. */ +#include #include -#include +#include #include -#include -#include "hilog/log.h" #include "napi/native_api.h" #include "napi/native_node_api.h" #include "syscap_interface.h" diff --git a/src/create_pcid.c b/src/create_pcid.c index 8710a95..7926f93 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -17,12 +17,8 @@ #include #include #include -#include #include #include -#include -#include -#include #include #include "securec.h" #include "cJSON.h" diff --git a/src/endian_internal.c b/src/endian_internal.c index fc7301a..5da4f70 100644 --- a/src/endian_internal.c +++ b/src/endian_internal.c @@ -14,7 +14,6 @@ */ #include "endian_internal.h" -#include #define B_L_SWAP16(A) ((((uint16_t)(A) & 0xff00) >> 8) | (((uint16_t)(A) & 0x00ff) << 8)) #define B_L_SWAP32(A) ((((uint32_t)(A) & 0xff000000) >> 24) | (((uint32_t)(A) & 0x00ff0000) >> 8) | \ diff --git a/src/syscap_tool.c b/src/syscap_tool.c index fdfceb2..8f28bba 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -14,15 +14,11 @@ */ #include -#include #include #include #include -#include #include #include -#include -#include #include #include "securec.h" #include "endian_internal.h" diff --git a/test/unittest/common/include/syscap_codec_test.h b/test/unittest/common/include/syscap_codec_test.h index 6c53be6..2410fa1 100644 --- a/test/unittest/common/include/syscap_codec_test.h +++ b/test/unittest/common/include/syscap_codec_test.h @@ -16,8 +16,6 @@ #ifndef _SYSCAP_CODEC_TEST_H #define _SYSCAP_CODEC_TEST_H -#include - #ifdef __cplusplus #if __cplusplus extern "C" { diff --git a/test/unittest/common/syscap_codec_test.cpp b/test/unittest/common/syscap_codec_test.cpp index be73036..23df011 100644 --- a/test/unittest/common/syscap_codec_test.cpp +++ b/test/unittest/common/syscap_codec_test.cpp @@ -13,7 +13,8 @@ * limitations under the License. */ -#include +#include +#include #include "syscap_interface.h" #include "syscap_codec_test.h" @@ -45,7 +46,7 @@ HWTEST_F(SyscapCodecTest, EncodeOsSyscap, TestSize.Level1) */ HWTEST_F(SyscapCodecTest, EncodePrivateSyscap, TestSize.Level1) { - char *charPriInput = NULL; + char *charPriInput = nullptr; int priOutLen; EXPECT_TRUE(EncodePrivateSyscap(&charPriInput, &priOutLen)); free(charPriInput); @@ -59,7 +60,7 @@ HWTEST_F(SyscapCodecTest, EncodePrivateSyscap, TestSize.Level1) HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1) { int osSyscap[32] = {1, 3, 3}; - char (*osOutput)[SINGLE_SYSCAP_LEN] = NULL; + char (*osOutput)[SINGLE_SYSCAP_LEN] = nullptr; int decodeOsCnt; char expectOsOutput001[] = "SystemCapability.Account.AppAccount"; char expectOsOutput002[] = "SystemCapability.Account.OsAccount"; @@ -78,7 +79,7 @@ HWTEST_F(SyscapCodecTest, DecodeOsSyscap, TestSize.Level1) */ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1) { - char (*priOutput)[SINGLE_SYSCAP_LEN] = NULL; + char (*priOutput)[SINGLE_SYSCAP_LEN] = nullptr; char priSyscap[] = "Device.syscap1GEDR,Device.syscap2WREGW,Vendor.syscap3RGD,Vendor.syscap4RWEG,Vendor.syscap5REWGWE,"; int decodePriCnt; char expectPriOutput001[] = "SystemCapability.Device.syscap1GEDR"; @@ -104,15 +105,15 @@ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap, TestSize.Level1) */ HWTEST_F(SyscapCodecTest, DecodePrivateSyscap1, TestSize.Level1) { - char *charPriInput = NULL; - char (*priOutput)[SINGLE_SYSCAP_LEN] = NULL; + char *charPriInput = nullptr; + char (*priOutput)[SINGLE_SYSCAP_LEN] = nullptr; int priOutLen; int decodePriCnt; EXPECT_TRUE(EncodePrivateSyscap(&charPriInput, &priOutLen)); if (priOutLen == 0) { EXPECT_TRUE(DecodePrivateSyscap(charPriInput, &priOutput, &decodePriCnt)); - EXPECT_EQ((void *)priOutput, (void *)NULL); + EXPECT_EQ((void *)priOutput, (void *)nullptr); EXPECT_EQ(decodePriCnt, 0); free(priOutput); } @@ -148,7 +149,7 @@ HWTEST_F(SyscapCodecTest, ComparePcidString, TestSize.Level1) EXPECT_EQ(result.targetApiVersion, 0); EXPECT_EQ(result.missSyscapNum, 0); for (int i = 0; i < MAX_MISS_SYSCAP; i++) { - EXPECT_EQ((void *)result.syscap[i], (void *)NULL); + EXPECT_EQ((void *)result.syscap[i], (void *)nullptr); } } } // namespace Syscap -- Gitee