mirror of
https://github.com/openharmony/developtools_syscap_codec.git
synced 2026-08-27 10:21:25 -04:00
fix: modify for codecheck.
Signed-off-by: yudechen <chenyude@huawei.com> Change-Id: I958ff1debd07586cdeee83e4732a4aefcfab4651
This commit is contained in:
+24
-24
@@ -42,7 +42,7 @@ constexpr size_t KEY_BUFFER_SIZE = 32;
|
||||
napi_get_cb_info(env, info, &argc, argv, &thisVar, &data)
|
||||
|
||||
// Async Function Set
|
||||
struct systemCapabilityAsyncContext {
|
||||
struct SystemCapabilityAsyncContext {
|
||||
napi_env env = nullptr;
|
||||
napi_async_work work = nullptr;
|
||||
char key[KEY_BUFFER_SIZE] = { 0 };
|
||||
@@ -64,7 +64,7 @@ static char* getSystemCapability()
|
||||
uint32_t *osCapU32 = nullptr;
|
||||
char *priOutput = nullptr;
|
||||
char *temp = nullptr;
|
||||
char *allSyscapBUffer = nullptr;
|
||||
char *allSyscapBuffer = nullptr;
|
||||
char osCapArray[PCID_MAIN_U32][U32_TO_STR_MAX_LEN] = {};
|
||||
char (*priCapArray)[SINGLE_SYSCAP_LEN] = nullptr;
|
||||
|
||||
@@ -105,39 +105,39 @@ static char* getSystemCapability()
|
||||
sumLen += (PCID_MAIN_U32 + priCapArrayCnt + 1); // split with ','
|
||||
|
||||
// splicing string
|
||||
allSyscapBUffer = (char *)malloc(sumLen);
|
||||
if (allSyscapBUffer == nullptr) {
|
||||
allSyscapBuffer = (char *)malloc(sumLen);
|
||||
if (allSyscapBuffer == nullptr) {
|
||||
PRINT_ERR("malloc failed!");
|
||||
goto FREE_PRICAP_ARRAY;
|
||||
}
|
||||
err = memset_s(allSyscapBUffer, sumLen, 0, sumLen);
|
||||
err = memset_s(allSyscapBuffer, sumLen, 0, sumLen);
|
||||
if (err != EOK) {
|
||||
PRINT_ERR("memset failed!");
|
||||
free(allSyscapBUffer);
|
||||
allSyscapBUffer = nullptr;
|
||||
free(allSyscapBuffer);
|
||||
allSyscapBuffer = nullptr;
|
||||
goto FREE_PRICAP_ARRAY;
|
||||
}
|
||||
temp = *osCapArray;
|
||||
|
||||
for (size_t i = 1; i < PCID_MAIN_U32; i++) {
|
||||
retError = sprintf_s(allSyscapBUffer, sumLen, "%s,%s", temp, osCapArray[i]);
|
||||
retError = sprintf_s(allSyscapBuffer, sumLen, "%s,%s", temp, osCapArray[i]);
|
||||
if (retError == -1) {
|
||||
PRINT_ERR("splicing os syscap string failed.");
|
||||
free(allSyscapBUffer);
|
||||
allSyscapBUffer = nullptr;
|
||||
free(allSyscapBuffer);
|
||||
allSyscapBuffer = nullptr;
|
||||
goto FREE_PRICAP_ARRAY;
|
||||
}
|
||||
temp = allSyscapBUffer;
|
||||
temp = allSyscapBuffer;
|
||||
}
|
||||
for (int i = 0; i < priCapArrayCnt; i++) {
|
||||
retError = sprintf_s(allSyscapBUffer, sumLen, "%s,%s", temp, *(priCapArray + i));
|
||||
retError = sprintf_s(allSyscapBuffer, sumLen, "%s,%s", temp, *(priCapArray + i));
|
||||
if (retError == -1) {
|
||||
PRINT_ERR("splicing pri syscap string failed.");
|
||||
free(allSyscapBUffer);
|
||||
allSyscapBUffer = nullptr;
|
||||
free(allSyscapBuffer);
|
||||
allSyscapBuffer = nullptr;
|
||||
goto FREE_PRICAP_ARRAY;
|
||||
}
|
||||
temp = allSyscapBUffer;
|
||||
temp = allSyscapBuffer;
|
||||
}
|
||||
|
||||
FREE_PRICAP_ARRAY:
|
||||
@@ -145,7 +145,7 @@ FREE_PRICAP_ARRAY:
|
||||
FREE_PRIOUTPUT:
|
||||
free(priOutput);
|
||||
|
||||
return allSyscapBUffer;
|
||||
return allSyscapBuffer;
|
||||
}
|
||||
|
||||
napi_value QuerySystemCapability(napi_env env, napi_callback_info info)
|
||||
@@ -154,7 +154,7 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info)
|
||||
NAPI_ASSERT(env, argc <= 1, "too many parameters");
|
||||
napi_value result = nullptr;
|
||||
|
||||
systemCapabilityAsyncContext* asyncContext = new systemCapabilityAsyncContext();
|
||||
SystemCapabilityAsyncContext* asyncContext = new SystemCapabilityAsyncContext();
|
||||
|
||||
asyncContext->env = env;
|
||||
|
||||
@@ -178,7 +178,7 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info)
|
||||
napi_create_async_work(
|
||||
env, nullptr, resource,
|
||||
[](napi_env env, void* data) {
|
||||
systemCapabilityAsyncContext *asyncContext = (systemCapabilityAsyncContext *)data;
|
||||
SystemCapabilityAsyncContext *asyncContext = (SystemCapabilityAsyncContext *)data;
|
||||
char *syscapStr = getSystemCapability();
|
||||
if (syscapStr != nullptr) {
|
||||
asyncContext->value = syscapStr;
|
||||
@@ -188,8 +188,8 @@ napi_value QuerySystemCapability(napi_env env, napi_callback_info info)
|
||||
}
|
||||
},
|
||||
[](napi_env env, napi_status status, void* data) {
|
||||
systemCapabilityAsyncContext *asyncContext = (systemCapabilityAsyncContext *)data;
|
||||
napi_value result[2] = {0};
|
||||
SystemCapabilityAsyncContext *asyncContext = (SystemCapabilityAsyncContext *)data;
|
||||
napi_value result[2] = {nullptr, nullptr};
|
||||
if (!asyncContext->status) {
|
||||
napi_get_undefined(env, &result[0]);
|
||||
napi_create_string_utf8(env, asyncContext->value, strlen(asyncContext->value), &result[1]); // ?
|
||||
@@ -235,14 +235,14 @@ EXTERN_C_END
|
||||
/*
|
||||
* Module define
|
||||
*/
|
||||
static napi_module systemCapabilityModule = {
|
||||
static napi_module g_systemCapabilityModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = QuerryExport,
|
||||
.nm_modname = "systemCapability",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = {0},
|
||||
.nm_priv = nullptr,
|
||||
.reserved = {nullptr},
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -250,6 +250,6 @@ static napi_module systemCapabilityModule = {
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void systemCapabilityRegisterModule(void)
|
||||
{
|
||||
napi_module_register(&systemCapabilityModule);
|
||||
napi_module_register(&g_systemCapabilityModule);
|
||||
}
|
||||
}
|
||||
+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);
|
||||
size_t 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