aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2022-08-24 16:15:00 +0300
committerJoursoir <chat@joursoir.net>2022-08-24 16:18:12 +0300
commite0810c5c7ae73c5e12d20fb169507e121c6b01e1 (patch)
tree28a5a50ecbd39d5b565e328dcf8ca023f1548aba
parent175b115e233c2181759c2f8a291a42724c0c549e (diff)
downloadlock-password-e0810c5c7ae73c5e12d20fb169507e121c6b01e1.tar.gz
lock-password-e0810c5c7ae73c5e12d20fb169507e121c6b01e1.tar.bz2
lock-password-e0810c5c7ae73c5e12d20fb169507e121c6b01e1.zip
cmd_showtree: use a constant pointer to store the path
No need to allocate memory.
-rw-r--r--src/exec-cmd.c17
1 files changed, 4 insertions, 13 deletions
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;
}