Skip to content

Commit

Permalink
Include json::parse() in try-catch block
Browse files Browse the repository at this point in the history
To avoid unhandled exception if json::parse() fails.
  • Loading branch information
gvnnz committed Jan 27, 2024
1 parent c8c8740 commit 97ade6c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/core/patchFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,26 +416,26 @@ Patch deserialize(const std::string& filePath)
return patch;
}

nlohmann::json j = nlohmann::json::parse(ifs);

if (j[PATCH_KEY_HEADER] != "GIADAPTC")
try
{
patch.status = G_FILE_INVALID;
return patch;
}
nlohmann::json j = nlohmann::json::parse(ifs);

patch.version = {
static_cast<int>(j[PATCH_KEY_VERSION_MAJOR]),
static_cast<int>(j[PATCH_KEY_VERSION_MINOR]),
static_cast<int>(j[PATCH_KEY_VERSION_PATCH])};
if (patch.version < Patch::Version{0, 16, 0})
{
patch.status = G_FILE_UNSUPPORTED;
return patch;
}
if (j[PATCH_KEY_HEADER] != "GIADAPTC")
{
patch.status = G_FILE_INVALID;
return patch;
}

patch.version = {
static_cast<int>(j[PATCH_KEY_VERSION_MAJOR]),
static_cast<int>(j[PATCH_KEY_VERSION_MINOR]),
static_cast<int>(j[PATCH_KEY_VERSION_PATCH])};
if (patch.version < Patch::Version{0, 16, 0})
{
patch.status = G_FILE_UNSUPPORTED;
return patch;
}

try
{
readCommons_(patch, j);
readColumns_(patch, j);
readPlugins_(patch, j);
Expand Down

0 comments on commit 97ade6c

Please sign in to comment.