From 72086bdacc5a6d74966ce1ae4a843a32e05cb258 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Thu, 4 Apr 2024 01:36:33 +0200 Subject: [PATCH] btrfs-progs: scrub start: use local buffer for data file path in scrub_start() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by 'gcc -fanalyzer': cmds/scrub.c:1150:25: warning: use of possibly-NULL ‘path’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] Initialization of the datafile path is done from a static string but the strdup() call is not handled. Store the path directly to the buffer, it's later modified by mkdir_p(). Signed-off-by: David Sterba --- cmds/scrub.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmds/scrub.c b/cmds/scrub.c index 9e03d50b..03c1f7b1 100644 --- a/cmds/scrub.c +++ b/cmds/scrub.c @@ -1261,7 +1261,7 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, pthread_t t_prog; struct scrub_file_record **past_scrubs = NULL; struct scrub_file_record *last_scrub = NULL; - char *datafile = strdup(SCRUB_DATA_FILE); + char datafile[] = SCRUB_DATA_FILE; char fsid[BTRFS_UUID_UNPARSED_SIZE]; char sock_path[PATH_MAX] = ""; struct scrub_progress_cycle spc; @@ -1318,7 +1318,6 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv, datafile); do_record = false; } - free(datafile); path = argv[optind];