Make JSON reading safer

- Check that the file actually opened before reading it
- If the JSON was discarded, then make just use an empty object
This commit is contained in:
Pk11
2021-03-23 04:47:49 -05:00
parent 5343661069
commit 77edd99749
7 changed files with 65 additions and 39 deletions
+2
View File
@@ -231,6 +231,8 @@ void Store::LoadFromFile(const std::string &file) {
this->storeJson = nlohmann::json::parse(in, nullptr, false);
fclose(in);
if (this->storeJson.is_discarded())
this->storeJson = { };
/* Check, if valid. */
if (this->storeJson.contains("storeInfo") && this->storeJson.contains("storeContent")) {