buf.c: correctly handle unset environment variables

This commit is contained in:
Johan Malm 2021-10-11 22:28:06 +01:00
parent 71c8aa1361
commit aa4668c792

View file

@ -20,10 +20,9 @@ buf_expand_shell_variables(struct buf *s)
}
*p = '\0';
p = getenv(environment_variable.buf);
if (!p) {
goto out;
}
if (p) {
buf_add(&new, p);
}
i += strlen(environment_variable.buf);
} else if (s->buf[i] == '~') {
/* expand tilde */
@ -38,7 +37,6 @@ buf_expand_shell_variables(struct buf *s)
new.buf[new.len] = '\0';
}
}
out:
free(environment_variable.buf);
free(s->buf);
s->buf = new.buf;