summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-08-19 17:59:38 -0400
committerpommicket <pommicket@gmail.com>2022-08-19 17:59:38 -0400
commit8965fd92759602c1c92c025344c1bb801bc15043 (patch)
tree40b6d3f1d78920f59e20ea11c0876f3b5067c93c
parenteee61e9c6754947a7ddf7650ee045ea6ace57fa9 (diff)
fixed reading before abspath in path_full
no change to the behaviour of ted, just potentially (unlikely) fixing bad reads
-rw-r--r--util.c4
1 files changed, 3 insertions, 1 deletions
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) {