From 7ab7d68a26d3b31d72b33a04e58793f27f2ac94d Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Sat, 24 Aug 2019 07:15:21 +0200 Subject: [PATCH] calloc in fileutils --- client/fileutils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 52fd1539f..31e48601d 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -669,7 +669,7 @@ int searchAndList(const char *pm3dir, const char *ext) { char *searchFile(const char *pm3dir, const char *searchname) { // explicit absolute (/) or relative path (./) => try only to match it directly - char *filename = malloc(strlen(searchname) + 1); + char *filename = calloc(strlen(searchname) + 1, sizeof(char)); if (filename == NULL) return NULL; strcpy(filename, searchname); if (((strlen(filename) > 1) && (filename[0] == '/')) || @@ -690,7 +690,7 @@ char *searchFile(const char *pm3dir, const char *searchname) { // try pm3 dirs in current workdir (dev mode) const char *exec_path = get_my_executable_directory(); if (exec_path != NULL) { - char *path = malloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1); + char *path = calloc(strlen(exec_path) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, exec_path); @@ -706,7 +706,7 @@ char *searchFile(const char *pm3dir, const char *searchname) { // try pm3 dirs in user .proxmark3 (user mode) char *user_path = getenv("HOME"); if (user_path != NULL) { - char *path = malloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1); + char *path = calloc(strlen(user_path) + strlen(PM3_USER_DIRECTORY) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, user_path); @@ -722,7 +722,7 @@ char *searchFile(const char *pm3dir, const char *searchname) { } // try pm3 dirs in pm3 installation dir (install mode) { - char *path = malloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1); + char *path = calloc(strlen(PM3_SHARE_PATH) + strlen(pm3dir) + strlen(filename) + 1, sizeof(char)); if (path == NULL) goto out; strcpy(path, PM3_SHARE_PATH);