From 45e7a8ab373cdc77b91a762510de18d00d8e1abb Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Tue, 28 May 2024 20:41:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- src/syscap_tool.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index bcd09fd..e579d5e 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -132,18 +132,14 @@ static int32_t FreeAfterRPCIDEncode( return ret; } -int32_t RPCIDEncode(char *inputFile, char *outputPath) -{ - int32_t ret; +int32_t RPCIDEncode(char *inputFile, char *outputPath) { char *contextBuffer = NULL; uint32_t bufferLen, sysCapSize; - char *convertedBuffer = NULL; - uint32_t convertedBufLen = sizeof(RPCIDHead); struct JsonObjectSysCap gJsonObjectSysCap; gJsonObjectSysCap.cjsonObjectRoot = NULL; gJsonObjectSysCap.sysCapPtr = NULL; - ret = GetFileContext(inputFile, &contextBuffer, &bufferLen); + int32_t ret = GetFileContext(inputFile, &contextBuffer, &bufferLen); if (ret != 0) { PRINT_ERR("GetFileContext failed, input file : %s\n", inputFile); return ret; @@ -152,40 +148,46 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) gJsonObjectSysCap.cjsonObjectRoot = cJSON_ParseWithLength(contextBuffer, bufferLen); if (gJsonObjectSysCap.cjsonObjectRoot == NULL) { PRINT_ERR("cJSON_Parse failed, context buffer is:\n%s\n", contextBuffer); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, null, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } gJsonObjectSysCap.sysCapPtr = cJSON_GetObjectItem(gJsonObjectSysCap.cjsonObjectRoot, "syscap"); if (gJsonObjectSysCap.sysCapPtr == NULL || !cJSON_IsArray(gJsonObjectSysCap.sysCapPtr)) { PRINT_ERR("get \"syscap\" object failed.\n"); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, null, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - ret = cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr); - if (ret < 0) { + if (cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr) < 0) { PRINT_ERR("get \"syscap\" array size failed\n"); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, null, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - sysCapSize = (uint32_t)ret; + // 2, to save SysCaptype & SysCapLength + sysCapSize = (uint32_t) ret; + uint32_t convertedBufLen = sizeof(RPCIDHead); convertedBufLen += (2 * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LEN); - - convertedBuffer = (char *)malloc(convertedBufLen); + char *convertedBuffer = (char *) malloc(convertedBufLen); if (convertedBuffer == NULL) { PRINT_ERR("malloc failed\n"); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, + FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - (void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); + (void) memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); - ret = FillOsCapLength(convertedBuffer, contextBuffer, gJsonObjectSysCap, sysCapSize, ret); + ret = FillOsCapLength(convertedBuffer, contextBuffer, gJsonObjectSysCap, sysCapSize, ret); if (ret == -1) { - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer,FREE_CONVERT_OUT_RPCID_ENCODE, ret); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, + FREE_CONVERT_OUT_RPCID_ENCODE, ret); } ret = ConvertedContextSaveAsFile(outputPath, "rpcid.sc", convertedBuffer, convertedBufLen); if (ret != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.sc\n", outputPath); } - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer,FREE_CONVERT_OUT_RPCID_ENCODE, ret); + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, + FREE_CONVERT_OUT_RPCID_ENCODE, ret); } static int32_t ParseRpcidToJson(char *input, uint32_t inputLen, cJSON *rpcidJson) -- Gitee From 19b91a5b420cdb56d182a161bb357e022f3112c4 Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Tue, 28 May 2024 21:26:03 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- include/syscap_tool.h | 2 +- src/syscap_tool.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/syscap_tool.h b/include/syscap_tool.h index a606e32..e383c27 100644 --- a/include/syscap_tool.h +++ b/include/syscap_tool.h @@ -32,7 +32,7 @@ int32_t PCIDEncode(char *inputFile, char *outputPath); /* in: inputFile, file name format: .sc, out: outputPath/.json */ int32_t PCIDDecode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.sc */ -int32_t RPCIDEncode(char *inputFile, char *outputPath); +static int32_t RPCIDEncode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.json */ int32_t RPCIDDecode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.json */ diff --git a/src/syscap_tool.c b/src/syscap_tool.c index e579d5e..5322170 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -36,6 +36,7 @@ #define SYSCAP_PREFIX_LEN 17 #define SINGLE_FEAT_LEN (SINGLE_SYSCAP_LEN - SYSCAP_PREFIX_LEN) +#define DOUBLE_SPACE 2 #define UINT8_BIT 8 #define INT_BIT 32 #define RPCID_OUT_BUFFER 32 @@ -132,7 +133,8 @@ static int32_t FreeAfterRPCIDEncode( return ret; } -int32_t RPCIDEncode(char *inputFile, char *outputPath) { +static int32_t RPCIDEncode(char *inputFile, char *outputPath) +{ char *contextBuffer = NULL; uint32_t bufferLen, sysCapSize; struct JsonObjectSysCap gJsonObjectSysCap; @@ -168,7 +170,7 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) { // 2, to save SysCaptype & SysCapLength sysCapSize = (uint32_t) ret; uint32_t convertedBufLen = sizeof(RPCIDHead); - convertedBufLen += (2 * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LEN); + convertedBufLen += (DOUBLE_SPACE * sizeof(uint16_t) + sysCapSize * SINGLE_FEAT_LEN); char *convertedBuffer = (char *) malloc(convertedBufLen); if (convertedBuffer == NULL) { PRINT_ERR("malloc failed\n"); -- Gitee From f22de1c03eb60c189e996f6ebc7afb7b552c3abf Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Wed, 29 May 2024 09:51:29 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=8E=BB=E6=8E=89static=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- include/syscap_tool.h | 2 +- src/syscap_tool.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/syscap_tool.h b/include/syscap_tool.h index e383c27..a606e32 100644 --- a/include/syscap_tool.h +++ b/include/syscap_tool.h @@ -32,7 +32,7 @@ int32_t PCIDEncode(char *inputFile, char *outputPath); /* in: inputFile, file name format: .sc, out: outputPath/.json */ int32_t PCIDDecode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.sc */ -static int32_t RPCIDEncode(char *inputFile, char *outputPath); +int32_t RPCIDEncode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.json */ int32_t RPCIDDecode(char *inputFile, char *outputPath); /* in: inputFile, out: outputPath/rpcid.json */ diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 5322170..c5c0978 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -133,7 +133,7 @@ static int32_t FreeAfterRPCIDEncode( return ret; } -static int32_t RPCIDEncode(char *inputFile, char *outputPath) +int32_t RPCIDEncode(char *inputFile, char *outputPath) { char *contextBuffer = NULL; uint32_t bufferLen, sysCapSize; -- Gitee From b3f5e55f884a15e533b3f1b6e1723e7020c29f3a Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Wed, 29 May 2024 10:11:32 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=B0=86null=E6=94=B9=E6=88=90NULL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- src/syscap_tool.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index c5c0978..fb4ba32 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -150,20 +150,20 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) gJsonObjectSysCap.cjsonObjectRoot = cJSON_ParseWithLength(contextBuffer, bufferLen); if (gJsonObjectSysCap.cjsonObjectRoot == NULL) { PRINT_ERR("cJSON_Parse failed, context buffer is:\n%s\n", contextBuffer); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, null, contextBuffer, + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } gJsonObjectSysCap.sysCapPtr = cJSON_GetObjectItem(gJsonObjectSysCap.cjsonObjectRoot, "syscap"); if (gJsonObjectSysCap.sysCapPtr == NULL || !cJSON_IsArray(gJsonObjectSysCap.sysCapPtr)) { PRINT_ERR("get \"syscap\" object failed.\n"); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, null, contextBuffer, + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } if (cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr) < 0) { PRINT_ERR("get \"syscap\" array size failed\n"); - return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, null, contextBuffer, + return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } -- Gitee From 78c12828653957cf0a3157ae55138f5e0bc16cc2 Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Wed, 29 May 2024 10:29:26 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9rpcid.sc=E6=B2=A1?= =?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- src/syscap_tool.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/syscap_tool.c b/src/syscap_tool.c index fb4ba32..5663b64 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -161,7 +161,8 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) FREE_CONTEXT_OUT_RPCID_ENCODE, -1); } - if (cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr) < 0) { + ret = cJSON_GetArraySize(gJsonObjectSysCap.sysCapPtr); + if (ret < 0) { PRINT_ERR("get \"syscap\" array size failed\n"); return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, NULL, contextBuffer, FREE_CONTEXT_OUT_RPCID_ENCODE, -1); @@ -179,13 +180,11 @@ int32_t RPCIDEncode(char *inputFile, char *outputPath) } (void) memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen); - ret = FillOsCapLength(convertedBuffer, contextBuffer, gJsonObjectSysCap, sysCapSize, ret); - if (ret == -1) { + if (FillOsCapLength(convertedBuffer, contextBuffer, gJsonObjectSysCap, sysCapSize, ret) == -1) { return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, FREE_CONVERT_OUT_RPCID_ENCODE, ret); } - ret = ConvertedContextSaveAsFile(outputPath, "rpcid.sc", convertedBuffer, convertedBufLen); - if (ret != 0) { + if (ConvertedContextSaveAsFile(outputPath, "rpcid.sc", convertedBuffer, convertedBufLen) != 0) { PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.sc\n", outputPath); } return FreeAfterRPCIDEncode(gJsonObjectSysCap.cjsonObjectRoot, convertedBuffer, contextBuffer, -- Gitee