diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-11-01 04:38:12 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-11-01 04:38:12 +0300 |
commit | d4d38e8a34e59c8762034073b084ed3c5ee09af8 (patch) | |
tree | 8be8eec9fd0ac2ac35e1d9f58deb00baa4f305bf /source/blender/blenlib/intern | |
parent | a06abbac92f2029269375ced69a2c4f75ecce5e1 (diff) |
BLI_path_util: assert to ensure BLI_join_dirfile is used correctly
Diffstat (limited to 'source/blender/blenlib/intern')
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 2403d34e5d7..182fe211110 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1730,6 +1730,9 @@ void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__re /** * Simple appending of filename to dir, does not check for valid path! * Puts result into `dst`, which may be same area as `dir`. + * + * \note Consider using #BLI_path_join for more general path joining + * that de-duplicates separators and can handle an arbitrary number of paths. */ void BLI_join_dirfile(char *__restrict dst, const size_t maxlen, @@ -1741,9 +1744,13 @@ void BLI_join_dirfile(char *__restrict dst, #endif size_t dirlen = BLI_strnlen(dir, maxlen); - /* args can't match */ + /* Arguments can't match. */ BLI_assert(!ELEM(dst, dir, file)); + /* Files starting with a separator cause a double-slash which could later be interpreted + * as a relative path where: `dir == "/"` and `file == "/file"` would result in "//file". */ + BLI_assert(file[0] != SEP); + if (dirlen == maxlen) { memcpy(dst, dir, dirlen); dst[dirlen - 1] = '\0'; |