From 3effa5733b7bed5c983c9c0a1490fa7f7f37fc07 Mon Sep 17 00:00:00 2001 From: yudechen Date: Fri, 14 Jul 2023 16:23:19 +0800 Subject: [PATCH] fix: fix the order of g_arraySyscap. Signed-off-by: yudechen Change-Id: Id26071b0c05915ebd46b0bce8b4153dd323b6ef3 --- interfaces/inner_api/syscap_interface.c | 27 ++++++++++++++++--------- src/syscap_tool.c | 18 ++++++++++++++--- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c index e98c396..976bfeb 100644 --- a/interfaces/inner_api/syscap_interface.c +++ b/interfaces/inner_api/syscap_interface.c @@ -557,10 +557,11 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa char *rpcidPriSyscap = NULL; bool priSysFound; uint32_t pcidPriSyscapLen, rpcidPriSyscapLen; - uint32_t i, j, temp1, temp2; + uint32_t i, j; uint32_t retFlag = 0; uint32_t pcidOsAarry[PCID_OUT_BUFFER] = {0}; uint32_t rpcidOsAarry[PCID_OUT_BUFFER] = {0}; + const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); ret = SeparateSyscapFromString(pcidString, pcidOsAarry, PCID_OUT_BUFFER, &pcidPriSyscap, &pcidPriSyscapLen); @@ -580,27 +581,33 @@ int32_t ComparePcidString(const char *pcidString, const char *rpcidString, Compa } // compare os sysscap for (i = 2; i < PCID_OUT_BUFFER; i++) { // 2, header of pcid & rpcid - temp1 = pcidOsAarry[i] ^ rpcidOsAarry[i]; - temp2 = temp1 & rpcidOsAarry[i]; - if (!temp2) { + uint32_t blockBits = (pcidOsAarry[i] ^ rpcidOsAarry[i]) & rpcidOsAarry[i]; + if (!blockBits) { continue; } for (uint8_t k = 0; k < INT_BIT; k++) { - if (temp2 & (1U << k)) { - char *temp = (char *)malloc(sizeof(char) * SINGLE_SYSCAP_LEN); - if (temp == NULL) { + if (blockBits & (1U << k)) { + char *tempSyscap = (char *)malloc(sizeof(char) * SINGLE_SYSCAP_LEN); + if (tempSyscap == NULL) { PRINT_ERR("malloc failed.\n"); FreeCompareError(result); return -1; } - ret = strcpy_s(temp, sizeof(char) * SINGLE_SYSCAP_LEN, - g_arraySyscap[(i - 2) * INT_BIT + k].str); // 2, header of pcid & rpcid + uint32_t pos = (i - 2) * INT_BIT + k; + uint32_t t_; + for (t_ = 0; t_ < allSyscapNum; t_++) { + if (g_arraySyscap[t_].num == pos) { + break; + } + } + ret = strcpy_s(tempSyscap, sizeof(char) * SINGLE_SYSCAP_LEN, + g_arraySyscap[t_].str); // 2, header of pcid & rpcid if (ret != EOK) { PRINT_ERR("strcpy_s failed.\n"); FreeCompareError(result); return -1; } - result->syscap[ossyscapFlag++] = temp; + result->syscap[ossyscapFlag++] = tempSyscap; } } } diff --git a/src/syscap_tool.c b/src/syscap_tool.c index 2b5a656..0f83187 100644 --- a/src/syscap_tool.c +++ b/src/syscap_tool.c @@ -659,6 +659,17 @@ int32_t SeparateSyscapFromString(const char *inputString, uint32_t *osArray, uin return 0; } +int32_t GetSyscapByIndex(uint32_t index) +{ + const size_t allSyscapNum = sizeof(g_arraySyscap) / sizeof(SyscapWithNum); + for (uint32_t i = 0; i < allSyscapNum; i++) { + if (g_arraySyscap[i].num == index) { + return i; + } + } + return -1; +} + int32_t CompareOsSyscap(uint32_t pcidOsAarry[], uint32_t rpcidOsAarry[]) { int32_t ossyscapFlag = 0; @@ -675,10 +686,11 @@ int32_t CompareOsSyscap(uint32_t pcidOsAarry[], uint32_t rpcidOsAarry[]) } // 2, header of pcid & rpcid size_t pos = (size_t)((i - 2) * INT_BIT + k); - if (pos < allSyscapNum) { - printf("Missing: %s\n", g_arraySyscap[pos].str); - ossyscapFlag += 1; + if (pos >= allSyscapNum) { + break; } + printf("Missing: %s\n", g_arraySyscap[GetSyscapByIndex(pos)].str); + ossyscapFlag += 1; } } return ossyscapFlag; -- Gitee