modify for codex.

Signed-off-by: yudechen <chenyude@huawei.com>
Change-Id: Id06b50afe31eb2dcd53271b2907bb3f33946b453
This commit is contained in:
yudechen
2022-05-17 16:08:15 +08:00
parent e5a012de95
commit cb3ca3e397
6 changed files with 52 additions and 39 deletions
+14 -11
View File
@@ -47,9 +47,9 @@ static void FreeContextBuffer(char *contextBuffer)
(void)free(contextBuffer);
}
static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *contextBufLen)
static int32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *contextBufLen)
{
uint32_t ret;
int32_t ret;
FILE *fp = NULL;
struct stat statBuf;
char *contextBuffer = NULL;
@@ -68,6 +68,7 @@ static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *
PRINT_ERR("malloc buffer failed, size = %d, errno = %d\n", (int32_t)statBuf.st_size + 1, errno);
return -1;
}
fp = fopen(inputFile, "rb");
if (fp == NULL) {
PRINT_ERR("open file(%s) failed, errno = %d\n", inputFile, errno);
@@ -107,6 +108,10 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename
fileFullPath[pathLen] = '/';
}
if (strlen(fileFullPath) + strlen(filename) + 1 > PATH_MAX) {
PRINT_ERR("length of path too long.\n");
return -1;
}
ret = strncat_s(fileFullPath, PATH_MAX, filename, strlen(filename) + 1);
if (ret != 0) {
PRINT_ERR("strncat_s failed, (%s, %d, %s, %d), errno = %d\n",
@@ -120,8 +125,7 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, const char *filename
return -1;
}
ret = fwrite(convertedBuffer, contextBufLen, 1, fp);
if (ret != 1) {
if (fwrite(convertedBuffer, contextBufLen, 1, fp) != 1) {
PRINT_ERR("can't write file(%s),errno = %d\n", fileFullPath, errno);
(void)fclose(fp);
return -1;
@@ -144,9 +148,8 @@ static cJSON *CreateWholeSyscapJsonObj(void)
int32_t CreatePCID(char *inputFile, char *outDirPath)
{
uint8_t sectorOfBits, posOfBits;
int32_t ret, i;
uint32_t contextBufLen, osCapSize, privateCapSize;
int32_t ret, osCapSize, sectorOfBits, posOfBits;
uint32_t i, contextBufLen, privateCapSize;
errno_t nRet = 0;
char *contextBuffer = NULL;
char *systemType = NULL;
@@ -268,7 +271,7 @@ int32_t CreatePCID(char *inputFile, char *outDirPath)
jsonSyscapObj = cJSON_GetObjectItem(jsonRootObj, "system_type");
if (jsonSyscapObj == NULL || !cJSON_IsString(jsonSyscapObj)) {
PRINT_ERR("get \"system_type\" failed, jsonSyscapObj = %p\n", jsonSyscapObj);
PRINT_ERR("get \"system_type\" failed\n");
ret = -1;
goto FREE_PCID_BUFFER_OUT;
}
@@ -308,12 +311,12 @@ FREE_CONVERT_OUT:
int32_t DecodePCID(char *inputFile, char *outDirPath)
{
int32_t ret, i, j;
int32_t ret;
errno_t nRet = 0;
char *contextBuffer = NULL;
uint8_t osSyscap[BYTES_OF_OS_SYSCAP] = {0};
uint16_t indexOfSyscap[960] = {0};
uint32_t contextBufLen, countOfSyscap = 0;
uint16_t indexOfSyscap[BYTES_OF_OS_SYSCAP * BITS_OF_ONE_BYTE] = {0};
uint32_t i, j, contextBufLen, countOfSyscap = 0;
ret = GetFileContext(inputFile, &contextBuffer, &contextBufLen);
if (ret != 0) {
+19 -12
View File
@@ -54,9 +54,9 @@ static void FreeContextBuffer(char *contextBuffer)
(void)free(contextBuffer);
}
static uint32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *bufferLen)
static int32_t GetFileContext(char *inputFile, char **contextBufPtr, uint32_t *bufferLen)
{
uint32_t ret;
int32_t ret;
FILE *fp = NULL;
struct stat statBuf;
char *contextBuffer = NULL;
@@ -113,6 +113,10 @@ static int32_t ConvertedContextSaveAsFile(char *outDirPath, char *filename, char
fileFullPath[pathLen] = '/';
}
if (strlen(filename) + 1 > PATH_MAX) {
PRINT_ERR("filename(%s) too long.\n", filename);
return -1;
}
ret = strncat_s(fileFullPath, PATH_MAX, filename, strlen(filename) + 1);
if (ret != 0) {
PRINT_ERR("strncat_s failed, (%s, %d, %s, %d), errno = %d\n",
@@ -143,11 +147,10 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
int32_t ret;
char productName[NAME_MAX] = {0};
char *contextBuffer = NULL;
uint32_t bufferLen;
uint32_t bufferLen, osCapSize, privateCapSize;
char *convertedBuffer = NULL;
uint32_t convertedBufLen = sizeof(PCIDHead);
char *systemType = NULL;
int32_t osCapSize, privateCapSize;
PCIDHead *headPtr = NULL;
char *fillTmpPtr = NULL;
cJSON *cjsonObjectRoot = NULL;
@@ -206,6 +209,11 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
}
convertedBuffer = (char *)malloc(convertedBufLen);
if (convertedBuffer == NULL) {
PRINT_ERR("malloc failed.\n");
ret = -1;
goto FREE_CONTEXT_OUT;
}
(void)memset_s(convertedBuffer, convertedBufLen, 0, convertedBufLen);
@@ -250,7 +258,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
// fill osCap Length
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(osCapSize * SINGLE_FEAT_LENGTH));
fillTmpPtr += sizeof(uint16_t);
for (int32_t i = 0; i < osCapSize; i++) {
for (uint32_t i = 0; i < osCapSize; i++) {
arrayItemPtr = cJSON_GetArrayItem(osCapPtr, i);
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
if (pointPos == NULL) {
@@ -280,7 +288,7 @@ int32_t PCIDEncode(char *inputFile, char *outDirPath)
// fill privateCap Length
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(privateCapSize * SINGLE_FEAT_LENGTH));
fillTmpPtr += sizeof(uint16_t);
for (int32_t i = 0; i < privateCapSize; i++) {
for (uint32_t i = 0; i < privateCapSize; i++) {
arrayItemPtr = cJSON_GetArrayItem(privateCapPtr, i);
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
if (pointPos == NULL) {
@@ -425,7 +433,7 @@ int32_t PCIDDecode(char *inputFile, char *outDirPath)
ret = -1;
goto FREE_SYSCAP_OUT;
}
for (int32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
for (uint32_t i = 0; i < (sysCapLength / SINGLE_FEAT_LENGTH); i++) {
if (*(osCapArrayPtr + (i + 1) * SINGLE_FEAT_LENGTH - 1) != '\0') {
PRINT_ERR("prase file failed, format is invalid, input file : %s\n", inputFile);
ret = -1;
@@ -569,10 +577,9 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
{
int32_t ret;
char *contextBuffer = NULL;
uint32_t bufferLen;
uint32_t bufferLen, sysCapSize;
char *convertedBuffer = NULL;
uint32_t convertedBufLen = sizeof(RPCIDHead);
int32_t sysCapSize;
RPCIDHead *headPtr = NULL;
char *fillTmpPtr = NULL;
cJSON *cjsonObjectRoot = NULL;
@@ -595,7 +602,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
sysCapPtr = cJSON_GetObjectItem(cjsonObjectRoot, "syscap");
if (sysCapPtr == NULL || !cJSON_IsArray(sysCapPtr)) {
PRINT_ERR("get \"syscap\" object failed, sysCapPtr = %p\n", sysCapPtr);
PRINT_ERR("get \"syscap\" object failed.\n");
ret = -1;
goto FREE_CONTEXT_OUT;
}
@@ -629,7 +636,7 @@ int32_t RPCIDEncode(char *inputFile, char *outDirPath)
// fill osCap Length
*(uint16_t *)fillTmpPtr = HtonsInter((uint16_t)(sysCapSize * SINGLE_FEAT_LENGTH));
fillTmpPtr += sizeof(uint16_t);
for (int32_t i = 0; i < sysCapSize; i++) {
for (uint32_t i = 0; i < sysCapSize; i++) {
arrayItemPtr = cJSON_GetArrayItem(sysCapPtr, i);
char *pointPos = strchr(arrayItemPtr->valuestring, '.');
if (pointPos == NULL) {
@@ -668,7 +675,7 @@ FREE_CONTEXT_OUT:
int32_t RPCIDDecode(char *inputFile, char *outDirPath)
{
uint32_t ret;
int32_t ret;
char *contextBuffer = NULL;
char *contextBufferTail = NULL;
uint32_t bufferLen;