From ff0c0211629668eff74dd4bdded861510e67b2eb Mon Sep 17 00:00:00 2001 From: vldmr11080 <57061786+vldmr11080@users.noreply.github.com> Date: Wed, 18 Mar 2020 11:17:57 +0100 Subject: [PATCH] Check if settings file is open before parsing JSON content from it (#1616) --- src/common/json.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/common/json.cpp b/src/common/json.cpp index b8c06d73aa..4fbbf9adc7 100644 --- a/src/common/json.cpp +++ b/src/common/json.cpp @@ -10,8 +10,12 @@ namespace json try { std::wifstream file(file_name.data(), std::ios::binary); - using isbi = std::istreambuf_iterator; - return JsonValue::Parse(std::wstring{ isbi{ file }, isbi{} }).GetObjectW(); + if (file.is_open()) + { + using isbi = std::istreambuf_iterator; + return JsonValue::Parse(std::wstring{ isbi{ file }, isbi{} }).GetObjectW(); + } + return std::nullopt; } catch (...) {