From f0b4e6651ca5f28ee69cf37370f4093034aff3f4 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 26 Mar 2021 21:47:13 +0100 Subject: [PATCH] fix cppchecker - null checks --- client/src/proxmark3.c | 4 ++++ client/src/scripting.c | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index f5d487fc7..e804972f4 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -519,6 +519,10 @@ static void set_my_user_directory(void) { uint16_t pathLen = FILENAME_MAX; // should be a good starting point char *cwd_buffer = (char *)calloc(pathLen, sizeof(uint8_t)); + if (cwd_buffer == NULL) { + PrintAndLogEx(WARNING, "failed to allocate memory"); + return; + } while (GetCurrentDir(cwd_buffer, pathLen) == NULL) { if (errno == ERANGE) { // Need bigger buffer diff --git a/client/src/scripting.c b/client/src/scripting.c index 6ac012199..9287e1f31 100644 --- a/client/src/scripting.c +++ b/client/src/scripting.c @@ -1279,10 +1279,12 @@ static int l_ewd(lua_State *L) { static int l_cwd(lua_State *L) { uint16_t path_len = FILENAME_MAX; // should be a good starting point - bool error = false; char *cwd = (char *)calloc(path_len, sizeof(uint8_t)); + if (cwd == NULL) { + return returnToLuaWithError(L, "Failed to allocate memory"); + } - while (!error && (GetCurrentDir(cwd, path_len) == NULL)) { + while (GetCurrentDir(cwd, path_len) == NULL) { if (errno == ERANGE) { // Need bigger buffer path_len += 10; // if buffer was too small add 10 characters and try again cwd = realloc(cwd, path_len);