mirror of
https://github.com/openharmony/developtools_syscap_codec.git
synced 2026-08-28 04:40:02 -04:00
fix: modify for codecheck.
Signed-off-by: yudechen <chenyude@huawei.com> Change-Id: I958ff1debd07586cdeee83e4732a4aefcfab4651
This commit is contained in:
+22
-22
@@ -231,8 +231,8 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
|
||||
uint16_t allPriSyscapStrLen = 0;
|
||||
for (i = 0; i < privateCapSize; i++) {
|
||||
jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, i);
|
||||
allPriSyscapStrLen += strlen(strchr(jsonArrayItem->valuestring, '.') + 1);
|
||||
jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i);
|
||||
allPriSyscapStrLen += (uint16_t)strlen(strchr(jsonArrayItem->valuestring, '.') + 1);
|
||||
allPriSyscapStrLen++; // for separator ','
|
||||
}
|
||||
if ((allPriSyscapStrLen + 1) > PRIVATE_SYSCAP_SIZE) {
|
||||
@@ -241,18 +241,18 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
goto FREE_CONVERT_OUT;
|
||||
}
|
||||
|
||||
uint16_t PCIDLength = sizeof(PCIDMain) + allPriSyscapStrLen + 1;
|
||||
PCIDMain *PCIDBuffer = (PCIDMain *)malloc(PCIDLength);
|
||||
if (PCIDBuffer == NULL) {
|
||||
uint16_t pcidLength = sizeof(PCIDMain) + allPriSyscapStrLen + 1;
|
||||
PCIDMain *pcidBuffer = (PCIDMain *)malloc(pcidLength);
|
||||
if (pcidBuffer == NULL) {
|
||||
PRINT_ERR("malloc for pcid buffer failed\n");
|
||||
ret = -1;
|
||||
goto FREE_CONVERT_OUT;
|
||||
}
|
||||
(void)memset_s(PCIDBuffer, PCIDLength, 0, PCIDLength);
|
||||
(void)memset_s(pcidBuffer, pcidLength, 0, pcidLength);
|
||||
|
||||
// process os syscap
|
||||
for (i = 0; i < osCapSize; i++) {
|
||||
jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, i);
|
||||
jsonArrayItem = cJSON_GetArrayItem(jsonOsSyscapObj, (int)i);
|
||||
osCapIndex = cJSON_GetObjectItem(allOsSyscapObj, jsonArrayItem->valuestring);
|
||||
if (osCapIndex == NULL) {
|
||||
PRINT_ERR("can't find the syscap: %s, please add it in syscap_define.h.\n", jsonArrayItem->valuestring);
|
||||
@@ -266,14 +266,14 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
ret = -1;
|
||||
goto FREE_PCID_BUFFER_OUT;
|
||||
}
|
||||
PCIDBuffer->osSyscap[sectorOfBits] |= 1 << (posOfBits);
|
||||
pcidBuffer->osSyscap[sectorOfBits] |= 1 << (posOfBits);
|
||||
}
|
||||
|
||||
// process private syscap
|
||||
char *priSyscapHead = (char *)(PCIDBuffer + 1);
|
||||
char *priSyscapHead = (char *)(pcidBuffer + 1);
|
||||
char *priSyscapStr = NULL;
|
||||
for (i = 0; i < privateCapSize; i++) {
|
||||
jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, i);
|
||||
jsonArrayItem = cJSON_GetArrayItem(jsonPriSyscapObj, (int)i);
|
||||
priSyscapStr = strchr(jsonArrayItem->valuestring, '.') + 1;
|
||||
nRet = strcat_s(priSyscapHead, allPriSyscapStrLen + 1, priSyscapStr);
|
||||
nRet += strcat_s(priSyscapHead, allPriSyscapStrLen + 1, ",");
|
||||
@@ -290,8 +290,8 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
ret = -1;
|
||||
goto FREE_PCID_BUFFER_OUT;
|
||||
}
|
||||
PCIDBuffer->apiVersion = HtonsInter((uint16_t)jsonSyscapObj->valueint);
|
||||
PCIDBuffer->apiVersionType = 0;
|
||||
pcidBuffer->apiVersion = HtonsInter((uint16_t)jsonSyscapObj->valueint);
|
||||
pcidBuffer->apiVersionType = 0;
|
||||
|
||||
jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type");
|
||||
if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) {
|
||||
@@ -300,10 +300,10 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
goto FREE_PCID_BUFFER_OUT;
|
||||
}
|
||||
systemType = jsonSyscapObj->valuestring;
|
||||
PCIDBuffer->systemType = !strcmp(systemType, "mini") ? 0b001 :
|
||||
pcidBuffer->systemType = !strcmp(systemType, "mini") ? 0b001 :
|
||||
(!strcmp(systemType, "small") ? 0b010 :
|
||||
(!strcmp(systemType, "standard") ? 0b100 : 0));
|
||||
if (PCIDBuffer->systemType == 0) {
|
||||
if (pcidBuffer->systemType == 0) {
|
||||
PRINT_ERR("\"system_type\" is invaild, systemType = \"%s\"\n", systemType);
|
||||
ret = -1;
|
||||
goto FREE_PCID_BUFFER_OUT;
|
||||
@@ -315,10 +315,10 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
ret = -1;
|
||||
goto FREE_PCID_BUFFER_OUT;
|
||||
}
|
||||
PCIDBuffer->manufacturerID = HtonlInter((uint32_t)jsonSyscapObj->valueint);
|
||||
pcidBuffer->manufacturerID = HtonlInter((uint32_t)jsonSyscapObj->valueint);
|
||||
|
||||
const char pcidFileName[] = "PCID.sc";
|
||||
ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)PCIDBuffer, PCIDLength);
|
||||
ret = ConvertedContextSaveAsFile(outDirPath, pcidFileName, (char *)pcidBuffer, pcidLength);
|
||||
if (ret != 0) {
|
||||
PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:%s\n", outDirPath, pcidFileName);
|
||||
ret = -1;
|
||||
@@ -326,7 +326,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
|
||||
}
|
||||
|
||||
FREE_PCID_BUFFER_OUT:
|
||||
free(PCIDBuffer);
|
||||
free(pcidBuffer);
|
||||
FREE_CONVERT_OUT:
|
||||
free(allOsSyscapObj);
|
||||
FreeContextBuffer(contextBuffer);
|
||||
@@ -376,7 +376,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
}
|
||||
|
||||
nRet = memcpy_s(osSyscap, OS_SYSCAP_BYTES, (uint8_t *)pcidMain + 8, OS_SYSCAP_BYTES); // 8, bytes of pcid header
|
||||
if (EOK != nRet) {
|
||||
if (nRet != EOK) {
|
||||
PRINT_ERR("memcpy_s failed.");
|
||||
ret = -1;
|
||||
goto FREE_VECTOR_OUT;
|
||||
@@ -420,7 +420,7 @@ int32_t DecodePCID(char *inputFile, char *outDirPath)
|
||||
}
|
||||
|
||||
char *ptrPrivateSyscap = (char *)(pcidMain + 1);
|
||||
int privateSyscapLen = contextBufLen - sizeof(PCIDMain) - 1;
|
||||
int privateSyscapLen = (int)(contextBufLen - sizeof(PCIDMain) - 1);
|
||||
char priSyscapStr[SINGLE_SYSCAP_LEN] = {0};
|
||||
char *tempPriSyscapStr = priSyscapStr;
|
||||
char fullPriSyscapStr[SINGLE_SYSCAP_LEN] = {0};
|
||||
@@ -694,15 +694,15 @@ int32_t DecodeStringPCIDToJson(char *input, char *outDirPath)
|
||||
PRINT_ERR("Add syscap to json failed.\n");
|
||||
goto ADD_JSON_FAILED;
|
||||
}
|
||||
if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj)) {
|
||||
if (AddHeaderToJsonObj(pcidHeader, PCID_HEADER, rootObj) != 0) {
|
||||
PRINT_ERR("Add header to json object failed.\n");
|
||||
goto ADD_JSON_FAILED;
|
||||
}
|
||||
if (AddOsSyscapToJsonObj(osSyscapUintArray, OS_SYSCAP_NUM, sysCapObj)) {
|
||||
if (AddOsSyscapToJsonObj(osSyscapUintArray, OS_SYSCAP_NUM, sysCapObj) != 0) {
|
||||
PRINT_ERR("Add os syscap json object failed.\n");
|
||||
goto ADD_JSON_FAILED;
|
||||
}
|
||||
if (AddPriSyscapToJsonObj(priSyscapStr, strlen(priSyscapStr), sysCapObj)) {
|
||||
if (AddPriSyscapToJsonObj(priSyscapStr, (uint32_t)strlen(priSyscapStr), sysCapObj) != 0) {
|
||||
PRINT_ERR("Add private syscap json object failed.\n");
|
||||
goto ADD_JSON_FAILED;
|
||||
}
|
||||
|
||||
+13
-13
@@ -170,7 +170,7 @@ static cJSON *CreateWholeSyscapJsonObj(void)
|
||||
return root;
|
||||
}
|
||||
|
||||
int32_t RPCIDEncode(char *inputFile, char *outDirPath)
|
||||
int32_t RPCIDEncode(char *inputFile, char *outputPath)
|
||||
{
|
||||
int32_t ret;
|
||||
char *contextBuffer = NULL;
|
||||
@@ -240,7 +240,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
|
||||
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(sysCapSize * SINGLE_FEAT_LEN));
|
||||
fillTmpPtr += sizeof(uint16_t);
|
||||
for (uint32_t i = 0; i < sysCapSize; i++) {
|
||||
arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, i);
|
||||
arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, (int)i);
|
||||
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
|
||||
if (pointPos == NULL) {
|
||||
PRINT_ERR("context of \"syscap\" array is invalid\n");
|
||||
@@ -263,9 +263,9 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
|
||||
fillTmpPtr += SINGLE_FEAT_LEN;
|
||||
}
|
||||
|
||||
ret = ConvertedContextSaveAsFile(outDirPath, "RPCID.sc", convertedBuffer, convertedBufLen);
|
||||
ret = ConvertedContextSaveAsFile(outputPath, "RPCID.sc", convertedBuffer, convertedBufLen);
|
||||
if (ret != 0) {
|
||||
PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:rpcid.sc\n", outDirPath);
|
||||
PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.sc\n", outputPath);
|
||||
goto FREE_CONVERT_OUT;
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ static int32_t CheckRpcidFormat(char *inputFile, char **Buffer, uint32_t *Len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RPCIDDecode(char *inputFile, char *outDirPath)
|
||||
int32_t RPCIDDecode(char *inputFile, char *outputPath)
|
||||
{
|
||||
int32_t ret = 0;
|
||||
char *contextBuffer = NULL;
|
||||
@@ -375,16 +375,16 @@ int32_t RPCIDDecode(char *inputFile, char *outDirPath)
|
||||
|
||||
// parse rpcid to json
|
||||
cJSON *rpcidRoot = cJSON_CreateObject();
|
||||
if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot)) {
|
||||
if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot) != 0) {
|
||||
PRINT_ERR("Prase rpcid to json failed. Input failed: %s\n", inputFile);
|
||||
goto FREE_RPCID_ROOT;
|
||||
}
|
||||
|
||||
// save to json file
|
||||
convertedBuffer = cJSON_Print(rpcidRoot);
|
||||
ret = ConvertedContextSaveAsFile(outDirPath, "RPCID.json", convertedBuffer, strlen(convertedBuffer));
|
||||
ret = ConvertedContextSaveAsFile(outputPath, "RPCID.json", convertedBuffer, strlen(convertedBuffer));
|
||||
if (ret != 0) {
|
||||
PRINT_ERR("ConvertedContextSaveAsFile failed, outDirPath:%s, filename:rpcid.json\n", outDirPath);
|
||||
PRINT_ERR("ConvertedContextSaveAsFile failed, outputPath:%s, filename:rpcid.json\n", outputPath);
|
||||
goto FREE_RPCID_ROOT;
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath)
|
||||
|
||||
// parse rpcid to json
|
||||
rpcidRoot = cJSON_CreateObject();
|
||||
if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot)) {
|
||||
if (ParseRpcidToJson(contextBuffer, bufferLen, rpcidRoot) != 0) {
|
||||
PRINT_ERR("Prase rpcid to json failed. Input file: %s\n", inputFile);
|
||||
goto FREE_RPCID_ROOT;
|
||||
}
|
||||
@@ -466,17 +466,17 @@ int32_t EncodeRpcidscToString(char *inputFile, char *outDirPath)
|
||||
(void)memset_s(osSysCapIndex, sizeof(uint16_t) * sysCapArraySize,
|
||||
0, sizeof(uint16_t) * sysCapArraySize);
|
||||
// malloc for save private syscap string
|
||||
priSyscapArray = (char *)malloc(sysCapArraySize * SINGLE_SYSCAP_LEN);
|
||||
priSyscapArray = (char *)malloc((uint32_t)sysCapArraySize * SINGLE_SYSCAP_LEN);
|
||||
if (priSyscapArray == NULL) {
|
||||
PRINT_ERR("malloc(%d) failed.\n", sysCapArraySize * SINGLE_SYSCAP_LEN);
|
||||
goto FREE_MALLOC_OSSYSCAP;
|
||||
}
|
||||
(void)memset_s(priSyscapArray, sysCapArraySize * SINGLE_SYSCAP_LEN,
|
||||
0, sysCapArraySize * SINGLE_SYSCAP_LEN);
|
||||
(void)memset_s(priSyscapArray, (size_t)(sysCapArraySize * SINGLE_SYSCAP_LEN),
|
||||
0, (size_t)(sysCapArraySize * SINGLE_SYSCAP_LEN));
|
||||
priSyscap = priSyscapArray;
|
||||
// part os syscap and ptivate syscap
|
||||
for (i = 0; i < (uint32_t)sysCapArraySize; i++) {
|
||||
cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, i);
|
||||
cJSON *cJsonItem = cJSON_GetArrayItem(sysCapArray, (int)i);
|
||||
cJsonTemp = cJSON_GetObjectItem(sysCapDefine, cJsonItem->valuestring);
|
||||
if (cJsonTemp != NULL) {
|
||||
osSysCapIndex[indexOs++] = (uint16_t)(cJsonTemp->valueint);
|
||||
|
||||
Reference in New Issue
Block a user