From 1f2d73f922ac8faf040c8e72f03ba8b4ce27f63b Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Mon, 15 Jul 2024 21:07:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=B0=86calloc=E5=87=BD=E6=95=B0=E6=94=B9?= =?UTF-8?q?=E6=88=90malloc=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- 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 10400be..862b1e4 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -130,7 +130,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) FreeContextBuffer(contextBuffer); return false; } - outputStr = (char *)calloc(priLen, sizeof(char)); + outputStr = (char *)malloc(priLen * sizeof(char)); if (outputStr == NULL) { PRINT_ERR("malloc buffer failed, size = %u, errno = %d\n", priLen, errno); *outputLen = 0; -- Gitee From c219337456e2b17ace4567b77dbbfd7874952e57 Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Mon, 15 Jul 2024 21:08:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- BUILD.gn | 2 +- include/codec_config/syscap_define.h | 2 +- interfaces/inner_api/syscap_interface.c | 11 +++++------ src/create_pcid.c | 4 ++-- tools/syscap_collector.py | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 9d6fb40..870dbae 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/include/codec_config/syscap_define.h b/include/codec_config/syscap_define.h index 8fee30f..199984c 100644 --- a/include/codec_config/syscap_define.h +++ b/include/codec_config/syscap_define.h @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index 862b1e4..c89ce94 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -178,8 +178,7 @@ bool DecodeOsSyscap(const char input[PCID_MAIN_BYTES], char (**output)[SINGLE_SY *outputCnt = 0; return false; } - (void)memset_s(strSyscap, countOfSyscap * SINGLE_SYSCAP_LEN, \ - 0, countOfSyscap * SINGLE_SYSCAP_LEN); + (void)memset_s(strSyscap, countOfSyscap * SINGLE_SYSCAP_LEN, 0, countOfSyscap * SINGLE_SYSCAP_LEN); *output = strSyscap; for (i = 0; i < countOfSyscap; i++) { @@ -279,7 +278,7 @@ static int SetOsSysCapBitMap(uint8_t *out, uint16_t outLen, const uint16_t *inde PRINT_ERR("Syscap num(%u) out of range(120).\n", sector); return -1; } - out[sector] |= (1 << pos); + out[sector] |= (1 << pos); } return 0; } @@ -411,7 +410,7 @@ static void PartSysCapAndOutBuffer(struct FreeAfterDecodeRpcidInfo freeAfterDeco uint16_t indexPri = 0; cJSON *cJsonTemp = NULL; - freeAfterDecodeRpcidInfo.sysCapDefine = CreateWholeSyscapJsonObj(); + freeAfterDecodeRpcidInfo.sysCapDefine = CreateWholeSyscapJsonObj(); (void)memset_s(priSyscapArray, freeAfterDecodeRpcidInfo.sysCapArraySize * SINGLE_SYSCAP_LEN, 0, freeAfterDecodeRpcidInfo.sysCapArraySize * SINGLE_SYSCAP_LEN); freeAfterDecodeRpcidInfo.priSyscap = priSyscapArray; @@ -647,7 +646,7 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); - pcidPriSyscapInfo.ret = SeparateSyscapFromString(pcidString, pcidOsAarry, PCID_OUT_BUFFER, + pcidPriSyscapInfo.ret = SeparateSyscapFromString(pcidString, pcidOsAarry, PCID_OUT_BUFFER, &pcidPriSyscapInfo.pcidPriSyscap, &pcidPriSyscapInfo.pcidPriSyscapLen); pcidPriSyscapInfo.ret += SeparateSyscapFromString(rpcidString, rpcidOsAarry, RPCID_OUT_BUFFER, &pcidPriSyscapInfo.rpcidPriSyscap, &pcidPriSyscapInfo.rpcidPriSyscapLen); diff --git a/src/create_pcid.c b/src/create_pcid.c index 5316984..09aaa64 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -202,7 +202,7 @@ int32_t GetPriSyscapLen(uint32_t privateCapSize, cJSON *jsonPriSyscapObj, uint16 return -1; } *len += (uint16_t)strlen(strchr(jsonArrayItem->valuestring, '.') + 1); - (*len)++; // for separator ',' + (*len)++; // for separator ',' } if ((*len + 1) > PRIVATE_SYSCAP_SIZE) { PRINT_ERR("context of \"pri\" array is too many.\n"); @@ -347,7 +347,7 @@ int32_t GetOsSyscap(PCIDMain *pcidMain, cJSON *sysCapObject) return 0; } -static int32_t GetPriSyscapResult(cJSON* capVectorPtr, int32_t ret) +static int32_t GetPriSyscapResult(cJSON *capVectorPtr, int32_t ret) { cJSON_Delete(capVectorPtr); return ret; diff --git a/tools/syscap_collector.py b/tools/syscap_collector.py index bbc950f..9d9247c 100755 --- a/tools/syscap_collector.py +++ b/tools/syscap_collector.py @@ -47,7 +47,7 @@ def dict_to_json(output_path: str, syscaps_dict: dict): counts = Counter(syscaps_list) duplicates = [elem for elem, count in counts.items() if count > 1] if len(duplicates) > 0: - print("repeated syscap: " + ",".join(duplicates)) + print("[Warning] repeated syscap: {}".format(",".join(duplicates))) syscaps_list = list(set(syscaps_list)) filename = os.path.join(output_path, f'{product_name}.json') with os.fdopen(os.open(filename, flags, modes), 'w') as f: -- Gitee From fdefcdc96cb21741e8df43e13be683a8b27488bd Mon Sep 17 00:00:00 2001 From: liutuantuan Date: Thu, 18 Jul 2024 14:44:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=B0=86malloc=E5=87=BD=E6=95=B0=E6=94=B9?= =?UTF-8?q?=E5=9B=9Ecalloc=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liutuantuan --- 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 c89ce94..017eb5b 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -130,7 +130,7 @@ bool EncodePrivateSyscap(char **output, int *outputLen) FreeContextBuffer(contextBuffer); return false; } - outputStr = (char *)malloc(priLen * sizeof(char)); + outputStr = (char *)calloc(priLen, sizeof(char)); if (outputStr == NULL) { PRINT_ERR("malloc buffer failed, size = %u, errno = %d\n", priLen, errno); *outputLen = 0; -- Gitee