[Bf-blender-cvs] [d4d38e8a34e] blender-v3.0-release: BLI_path_util: assert to ensure BLI_join_dirfile is used correctly

Campbell Barton noreply at git.blender.org
Mon Nov 1 03:13:11 CET 2021


Commit: d4d38e8a34e59c8762034073b084ed3c5ee09af8
Author: Campbell Barton
Date:   Mon Nov 1 12:38:12 2021 +1100
Branches: blender-v3.0-release
https://developer.blender.org/rBd4d38e8a34e59c8762034073b084ed3c5ee09af8

BLI_path_util: assert to ensure BLI_join_dirfile is used correctly

===================================================================

M	source/blender/blenlib/intern/path_util.c

===================================================================

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';



More information about the Bf-blender-cvs mailing list