Skip to content

Commit 8cc8b72

Browse files
committed
utils: Use u8path to fix possible string conversion crashes on Windows
All other path operations in the code base already use u8path to ensure that the strings provided by libobs (which will either be ASCII or UTF-8 byte sequences) are correctly converted into UTF-16 strings.
1 parent eed8a49 commit 8cc8b72

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/utils/Json.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,11 @@ bool Utils::Json::GetJsonFileContent(std::string fileName, json &content)
195195

196196
bool Utils::Json::SetJsonFileContent(std::string fileName, const json &content, bool makeDirs)
197197
{
198+
auto jsonFilePath = std::filesystem::u8path(fileName);
199+
198200
if (makeDirs) {
201+
auto p = jsonFilePath.parent_path();
199202
std::error_code ec;
200-
auto p = std::filesystem::path(fileName).parent_path();
201203
if (!ec && !std::filesystem::exists(p, ec))
202204
std::filesystem::create_directories(p, ec);
203205
if (ec) {
@@ -207,7 +209,7 @@ bool Utils::Json::SetJsonFileContent(std::string fileName, const json &content,
207209
}
208210
}
209211

210-
std::ofstream f(fileName);
212+
std::ofstream f(jsonFilePath);
211213
if (!f.is_open()) {
212214
blog(LOG_ERROR, "[Utils::Json::SetJsonFileContent] Failed to open file `%s` for writing", fileName.c_str());
213215
return false;

0 commit comments

Comments
 (0)