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...
This commit is contained in:
Bastien Montagne 2015-01-16 18:48:59 +01:00
parent da8f16e288
commit 585275325e
Notes: blender-bot 2023-02-14 09:36:40 +01:00
Referenced by issue #43275, Crash on Render when using 'save buffer' and render layer name contains a '/'
3 changed files with 23 additions and 0 deletions

View File

@ -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();

View File

@ -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.

View File

@ -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);
}