From e2b83d6fdc5c45cb563f79397e8965edf11fe41c Mon Sep 17 00:00:00 2001 From: Ilya Shipitsin Date: Sat, 1 May 2021 20:19:57 +0500 Subject: Hamcore.c: handle memory allocation error Hamcore.c 284 warn V575 The potential null pointer is passed into 'memcpy' function. Inspect the first argument. Check lines: 284, 283. Hamcore.c 287 warn V575 The potential null pointer is passed into 'memcpy' function. Inspect the first argument. Check lines: 287, 286. Hamcore.c 235 warn V522 There might be dereferencing of a potential null pointer 'compressed_files'. Check lines: 235, 215. Hamcore.c 236 warn V522 There might be dereferencing of a potential null pointer 'compressed_file'. --- Hamcore.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Hamcore.c b/Hamcore.c index 04807f7..83a1ade 100644 --- a/Hamcore.c +++ b/Hamcore.c @@ -213,6 +213,10 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ } COMPRESSED_FILE *compressed_files = calloc(num, sizeof(COMPRESSED_FILE)); + if (!compressed_files) + { + return false; + } void *buffer = NULL; size_t buffer_size = 0; @@ -277,9 +281,23 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ const size_t path_size = strlen(relative_path) + 1; file->Path = malloc(path_size); + if (!file->Path) + { + free(compressed_files); + free(buffer); + return false; + } + memcpy(file->Path, relative_path, path_size); compressed_file->Data = malloc(file->Size); + if (!compressed_file->Data) + { + free(compressed_files); + free(buffer); + return false; + } + memcpy(compressed_file->Data, buffer, file->Size); } -- cgit v1.2.3