btrfs-progs: scrub start: use local buffer for data file path in scrub_start()

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 <dsterba@suse.com>
This commit is contained in:
David Sterba 2024-04-04 01:36:33 +02:00
parent 8767dda133
commit 72086bdacc
1 changed files with 1 additions and 2 deletions

View File

@ -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];