From 8965fd92759602c1c92c025344c1bb801bc15043 Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 19 Aug 2022 17:59:38 -0400 Subject: fixed reading before abspath in path_full no change to the behaviour of ted, just potentially (unlikely) fixing bad reads --- util.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/util.c b/util.c index 5008058..42d9387 100644 --- a/util.c +++ b/util.c @@ -265,6 +265,7 @@ static bool path_is_absolute(char const *path) { // assuming `dir` is an absolute path, returns the absolute path of `relpath`, relative to `dir`. static void path_full(char const *dir, char const *relpath, char *abspath, size_t abspath_size) { assert(abspath_size); + assert(dir[0]); abspath[0] = '\0'; if (path_is_absolute(relpath)) { @@ -281,7 +282,8 @@ static void path_full(char const *dir, char const *relpath, char *abspath, size_ } else { str_cpy(abspath, abspath_size, dir); } - if (abspath[strlen(abspath) - 1] != PATH_SEPARATOR) + + if (strlen(abspath) == 0 || abspath[strlen(abspath) - 1] != PATH_SEPARATOR) str_cat(abspath, abspath_size, PATH_SEPARATOR_STR); while (*relpath) { -- cgit v1.2.3