Commit: 585275325edb9988c9d6891c1fe571c63c81ceb1
Author: Bastien Montagne
Date:   Fri Jan 16 18:48:59 2015 +0100
Branches: master
https://developer.blender.org/rB585275325edb9988c9d6891c1fe571c63c81ceb1

Fix T43275: Crash on Render when using 'save buffer' and render layer name 
contains a '/'

Added a new BLI_path_utils func, `BLI_filename_make_safe()`, which for now 
simply
replaces unsafe chars for paths (like '\' or '/') by an underscore...

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

M       source/blender/blenlib/BLI_path_util.h
M       source/blender/blenlib/intern/path_util.c
M       source/blender/render/intern/source/render_result.c

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

diff --git a/source/blender/blenlib/BLI_path_util.h 
b/source/blender/blenlib/BLI_path_util.h
index bade390..8daaff1 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -108,6 +108,8 @@ void BLI_cleanup_dir(const char *relabase, char *dir) 
ATTR_NONNULL(2);
 /* doesn't touch trailing slash */
 void BLI_cleanup_path(const char *relabase, char *path) ATTR_NONNULL(2);
 
+void BLI_filename_make_safe(char *fname) ATTR_NONNULL(1);
+
 /* go back one directory */
 bool BLI_parent_dir(char *path) ATTR_NONNULL();
 
diff --git a/source/blender/blenlib/intern/path_util.c 
b/source/blender/blenlib/intern/path_util.c
index 3fff222..793f4d5 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -428,6 +428,24 @@ void BLI_cleanup_file(const char *relabase, char *path)
        BLI_del_slash(path);
 }
 
+
+/**
+ * Make given name safe to be used in paths.
+ *
+ * For now, simply replaces reserved chars (as listed in
+ * http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words )
+ * by underscores ('_').
+ */
+void BLI_filename_make_safe(char *fname)
+{
+       char *invalid = "/\\?%*:|\"<>. ";
+       char *c;
+
+       for (; *fname && (fname = strpbrk(fname, invalid)); fname++) {
+               *fname = '_';
+       }
+}
+
 /**
  * Does path begin with the special "//" prefix that Blender uses to indicate
  * a path relative to the .blend file.
diff --git a/source/blender/render/intern/source/render_result.c 
b/source/blender/render/intern/source/render_result.c
index de87fb2..154c0c8 100644
--- a/source/blender/render/intern/source/render_result.c
+++ b/source/blender/render/intern/source/render_result.c
@@ -1074,6 +1074,9 @@ void render_result_exr_file_path(Scene *scene, const char 
*layname, int sample,
                BLI_snprintf(name, sizeof(name), "%s_%s_%s%d.exr", fi, 
scene->id.name + 2, layname, sample);
        }
 
+       /* Make name safe for paths, see T43275. */
+       BLI_filename_make_safe(name);
+
        BLI_make_file_string("/", filepath, BKE_tempdir_session(), name);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to