From ea929641c2b215b19d7ccb582fc371a241fa932c Mon Sep 17 00:00:00 2001 From: doublelucky Date: Thu, 2 Jul 2026 20:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: doublelucky --- src/create_pcid.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/create_pcid.c b/src/create_pcid.c index fa94b40..2cddc9e 100644 --- a/src/create_pcid.c +++ b/src/create_pcid.c @@ -586,23 +586,27 @@ static int32_t AddHeaderToJsonObj(uint32_t *pcidHeader, uint32_t pcidHeaderLen, return -1; } - PCIDHeader *header = (PCIDHeader *)pcidHeader; + PCIDHeader header; + if (memcpy_s(&header, sizeof(header), pcidHeader, sizeof(PCIDHeader)) != 0) { + PRINT_ERR("Error: memcpy_s failed\n"); + return -1; + } // trans system type to string - char *systemType = header->systemType == 0b001 ? "mini" : - (header->systemType == 0b010 ? "small" : - (header->systemType == 0b100 ? "standard" : NULL)); + char *systemType = header.systemType == 0b001 ? "mini" : + (header.systemType == 0b010 ? "small" : + (header.systemType == 0b100 ? "standard" : NULL)); if (systemType == NULL) { PRINT_ERR("prase system type failed.\n"); return -1; } // add to json - if (!cJSON_AddNumberToObject(rootObj, "api_version", NtohsInter(header->apiVersion))) { - PRINT_ERR("add api_version(%u) to json object failed.\n", NtohsInter(header->apiVersion)); + if (!cJSON_AddNumberToObject(rootObj, "api_version", NtohsInter(header.apiVersion))) { + PRINT_ERR("add api_version(%u) to json object failed.\n", NtohsInter(header.apiVersion)); return -1; } - if (!cJSON_AddNumberToObject(rootObj, "manufacturer_id", NtohlInter(header->manufacturerID))) { - PRINT_ERR("add manufacturer_id(%u) to json object failed\n", NtohlInter(header->manufacturerID)); + if (!cJSON_AddNumberToObject(rootObj, "manufacturer_id", NtohlInter(header.manufacturerID))) { + PRINT_ERR("add manufacturer_id(%u) to json object failed\n", NtohlInter(header.manufacturerID)); return -1; } if (!cJSON_AddStringToObject(rootObj, "system_type", systemType)) {