From 27a3da2e70a6f543943302707ba03bd7185a53b3 Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Tue, 19 May 2020 07:32:41 -0400 Subject: [PATCH] UI: Fix GetUnusedSceneCollectionFile filename creation GetUnusedSceneCollectionFile tries to create a safe, unused filename for a new scene collection JSON file based on the user-specified scene collection name. It would check the length of the safe version of the user-specified name, but then it doesn't consider that the length may have changed when GetClosestUnusedFileName was called to alter the filename to prevent filename collisions by adding an incremented integer to the end of the filename. This could result in OBS thinking a filename was safe and available, but the resulting filename could be one that already exists. OBS could then overwrite a scene collection JSON file with this new file without any indication that the file previously existed. Instead of trying to calculate a length based off of the returned filename, let's just use the length of the config path since it's a known string. --- UI/window-basic-main-scene-collections.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UI/window-basic-main-scene-collections.cpp b/UI/window-basic-main-scene-collections.cpp index 9de9c84ca..126d0b19b 100644 --- a/UI/window-basic-main-scene-collections.cpp +++ b/UI/window-basic-main-scene-collections.cpp @@ -92,7 +92,6 @@ static bool SceneCollectionExists(const char *findName) static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file) { char path[512]; - size_t len; int ret; if (!GetFileSafeName(name.c_str(), file)) { @@ -107,7 +106,6 @@ static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file) return false; } - len = file.size(); file.insert(0, path); if (!GetClosestUnusedFileName(file, "json")) { @@ -117,7 +115,7 @@ static bool GetUnusedSceneCollectionFile(std::string &name, std::string &file) } file.erase(file.size() - 5, 5); - file.erase(0, file.size() - len); + file.erase(0, strlen(path)); return true; }