From c2cd1d5e381cdfdc0aec998d713e23397f445cf6 Mon Sep 17 00:00:00 2001 From: Robert Underwood Date: Mon, 21 Jun 2021 14:56:59 -0400 Subject: [PATCH] libpressio verison 0.66.3 Bug Fixes: + fixed several cases where JSON parsing errors could cause an uncaught exception in C --- CMakeLists.txt | 2 +- COPYRIGHT.txt | 2 +- src/pressio_options_json.cc | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8ed506e..dbc05434 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13 FATAL_ERROR) -project(libpressio VERSION "0.66.2" LANGUAGES CXX C) +project(libpressio VERSION "0.66.3" LANGUAGES CXX C) #correct was to set a default build type # https://blog.kitware.com/cmake-and-the-default-build-type/ diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt index c7cc450f..187e918c 100644 --- a/COPYRIGHT.txt +++ b/COPYRIGHT.txt @@ -1,6 +1,6 @@ Copyright © 2021 , UChicago Argonne, LLC All Rights Reserved -[libpressio, Version 0.65.0] +[libpressio, Version 0.66.3] Robert Underwood Argonne National Laboratory diff --git a/src/pressio_options_json.cc b/src/pressio_options_json.cc index 13b0e797..18d549ad 100644 --- a/src/pressio_options_json.cc +++ b/src/pressio_options_json.cc @@ -4,6 +4,7 @@ #include #include #include +#include void to_json(nlohmann::json& j, pressio_data const& data){ j["dims"] = data.dimensions(); @@ -256,10 +257,20 @@ void from_json(nlohmann::json const& j, pressio_options& options) { extern "C" { struct pressio_options* pressio_options_new_json(struct pressio* library, const char* json) { - nlohmann::json parsed = nlohmann::json::parse(json); pressio_options* options = nullptr; try { + nlohmann::json parsed = nlohmann::json::parse(json); options = new pressio_options(parsed.get()); + } catch (nlohmann::detail::out_of_range& ex) { + if(library) { + library->set_error(2, ex.what()); + } + } catch (nlohmann::detail::parse_error& ex) { + if(library) { + std::stringstream err_msg; + err_msg << ex.what() << "\n" << json; + library->set_error(2, err_msg.str()); + } } catch (std::runtime_error& ex) { if(library) { library->set_error(1, ex.what());