From e0810c5c7ae73c5e12d20fb169507e121c6b01e1 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Wed, 24 Aug 2022 16:15:00 +0300 Subject: cmd_showtree: use a constant pointer to store the path No need to allocate memory. --- src/exec-cmd.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/exec-cmd.c b/src/exec-cmd.c index c574b7b..570bdb5 100644 --- a/src/exec-cmd.c +++ b/src/exec-cmd.c @@ -487,7 +487,6 @@ int cmd_showtree(int argc, char *argv[]) const char description[] = "[-cC] [passname]\n"; int flag_copy = 0, flag_color = 1; int retval = 0, result; - char *path; const struct option long_options[] = { {"copy", no_argument, NULL, 'c'}, {"no-color", no_argument, NULL, 'C'}, @@ -504,18 +503,14 @@ int cmd_showtree(int argc, char *argv[]) } } + const char *path = "."; if(argv[optind]) { result = check_sneaky_paths(argv[optind]); if(result) { print_error("Error: You have used forbidden paths\n"); return 1; } - path = malloc(sizeof(char) * (strlen(argv[optind]) + 1)); - strcpy(path, argv[optind]); - } - else { - path = malloc(sizeof(char) * 2); - strcpy(path, "."); + path = argv[optind]; } result = file_exist(path); @@ -523,8 +518,7 @@ int cmd_showtree(int argc, char *argv[]) { if(flag_copy) { print_error("Error: You must type a passname, not a directory\n"); - retval = 1; - goto out; + return 1; } if(strcmp(path, ".") == 0) @@ -538,8 +532,7 @@ int cmd_showtree(int argc, char *argv[]) char *pass = get_password(path); if(!pass) { print_error("Error: Decrypt password failed\n"); - retval = 1; - goto out; + return 1; } if(flag_copy) @@ -554,7 +547,5 @@ int cmd_showtree(int argc, char *argv[]) retval = 1; } -out: - free(path); return retval; } -- cgit v1.2.3-18-g5258