From d4d38e8a34e59c8762034073b084ed3c5ee09af8 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 1 Nov 2021 12:38:12 +1100 Subject: BLI_path_util: assert to ensure BLI_join_dirfile is used correctly --- source/blender/blenlib/intern/path_util.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source/blender/blenlib/intern') 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'; -- cgit v1.2.3