diff options
author | pommicket <pommicket@gmail.com> | 2022-08-19 17:59:38 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-08-19 17:59:38 -0400 |
commit | 8965fd92759602c1c92c025344c1bb801bc15043 (patch) | |
tree | 40b6d3f1d78920f59e20ea11c0876f3b5067c93c /util.c | |
parent | eee61e9c6754947a7ddf7650ee045ea6ace57fa9 (diff) |
fixed reading before abspath in path_full
no change to the behaviour of ted, just potentially (unlikely)
fixing bad reads
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -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) { |