commit e3f1763154b647378a0f56d1d8f66b044a3552e1
parent aec9ca13ca6341919b2f2ea997dcdcf0a428f43b
Author: hhvn <dev@hhvn.uk>
Date: Mon, 23 May 2022 20:29:39 +0100
/alias -remove foo: remove /foo
Diffstat:
1 file changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/commands.c b/src/commands.c
@@ -1968,9 +1968,16 @@ alias_add(char *alias, char *cmd) {
int
alias_remove(char *alias) {
struct Alias *p;
+ char *tmp = NULL;
if (!alias)
return -1;
+ if (*alias != '/') {
+ tmp = emalloc(strlen(alias) + 2);
+ snprintf(tmp, strlen(alias) + 2, "/%s", alias);
+ alias = tmp;
+ /* tmp is guaranteed NULL or freeable */
+ };
for (p=aliases; p; p = p->next) {
if (strcmp(p->alias, alias) == 0) {
@@ -1985,6 +1992,7 @@ alias_remove(char *alias) {
pfree(&p->alias);
pfree(&p->cmd);
pfree(&p);
+ pfree(&tmp);
return 0;
}
}