From 319abb14eb69b2c8e549e83d15c0b6b5086ec96d Mon Sep 17 00:00:00 2001 From: BianTanggui Date: Mon, 21 Feb 2022 17:17:58 +0800 Subject: [PATCH] Match-id-fd706c08945c4519bcefe0d295d55c42c7ad1711 --- cli/src/basic.c | 5 +++++ install/deb/src/main.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/cli/src/basic.c b/cli/src/basic.c index 643cc9f..3af9c37 100644 --- a/cli/src/basic.c +++ b/cli/src/basic.c @@ -6,5 +6,10 @@ void InitParsedConfig(struct ParsedConfig *parsedConfig) { + if (parsedConfig != NULL) + { + Logger("parsedConfig Pointer is null!."); + return; + } parsedConfig->devicesNr = MAX_DEVICE_NR; } \ No newline at end of file diff --git a/install/deb/src/main.c b/install/deb/src/main.c index 2dd7a79..d3c8ee6 100644 --- a/install/deb/src/main.c +++ b/install/deb/src/main.c @@ -26,6 +26,10 @@ static void ReadJsonFile(FILE *pf, char *text, int maxBufferSize) { + if (pf == NULL || text == NULL) { + fprintf(stderr, "file pointer or text pointer are null!\n"); + return NULL; + } (void)fseek(pf, 0, SEEK_END); int size = (int)ftell(pf); @@ -43,6 +47,10 @@ static void ReadJsonFile(FILE *pf, char *text, int maxBufferSize) static cJSON *CreateAscendRuntimeInfo(const char *runtimePath) { + if (runtimePath = NULL) { + fprintf(stderr, "runtimePath pointer are null!\n"); + return NULL; + } cJSON *root = NULL; root = cJSON_CreateObject(); if (root == NULL) { @@ -75,6 +83,10 @@ static cJSON *CreateAscendRuntimeInfo(const char *runtimePath) static cJSON *CreateRuntimes(const char *runtimePath) { + if (runtimePath == NULL) { + fprintf(stderr, "runtimePath pointer is null!\n"); + return NULL; + } cJSON *ascendRuntime = NULL; ascendRuntime = CreateAscendRuntimeInfo(runtimePath); if (ascendRuntime == NULL) { @@ -97,6 +109,10 @@ static cJSON *CreateRuntimes(const char *runtimePath) static int DelJsonContent(cJSON *root, const char *key) { + if (root == NULL || key == NULL) { + fprintf(stderr, "userInfo pointer is null!\n"); + return NULL; + } cJSON *existItem = NULL; existItem = cJSON_GetObjectItem(root, key); if (existItem == NULL) { @@ -116,6 +132,10 @@ static int DelJsonContent(cJSON *root, const char *key) static cJSON *CreateContent(const char *runtimePath) { + if (runtimePath == NULL) { + fprintf(stderr, "runtimePath pointer is null!\n"); + return NULL; + } /* 插入ascend runtime */ cJSON *runtimes = NULL; runtimes = CreateRuntimes(runtimePath); @@ -150,6 +170,10 @@ static cJSON *CreateContent(const char *runtimePath) static cJSON *ModifyContent(FILE *pf, const char *runtimePath) { + if (pf == NULL || runtimePath == NULL) { + fprintf(stderr, "file pointer or runtimePath pointer is null!\n"); + return NULL; + } char jsonStr[MAX_JSON_FILE_SIZE] = {0x0}; ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE); @@ -203,6 +227,10 @@ static cJSON *ModifyContent(FILE *pf, const char *runtimePath) static cJSON *RemoveContent(FILE *pf) { + if (pf == NULL) { + fprintf(stderr, "file pointer is null!\n"); + return NULL; + } char jsonStr[MAX_JSON_FILE_SIZE] = {0x0}; ReadJsonFile(pf, &jsonStr[0], MAX_JSON_FILE_SIZE); @@ -241,6 +269,10 @@ static cJSON *RemoveContent(FILE *pf) static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, const char *runtimePath) { + if (filePath = NULL || tempPath = NULL || runtimePath = NULL) { + fprintf(stderr, "filePath Pointer or tempPath or runtimePath are null!\n"); + return -1; + } cJSON *root = NULL; FILE *pf = NULL; pf = fopen(filePath, "r+"); @@ -277,6 +309,10 @@ static int DetectAndCreateJsonFile(const char *filePath, const char *tempPath, c static int CreateRevisedJsonFile(const char *filePath, const char *tempPath) { + if (filePath == NULL || tempPath == NULL) { + fprintf(stderr, "filePath Pointer or tempPath are null!\n"); + return -1; + } FILE *pf = NULL; pf = fopen(filePath, "r+"); if (pf == NULL) {