From aeb66147da6a27d41790c938c38b040f71ee6d11 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 26 May 2020 13:33:59 +0100 Subject: [PATCH] json_serializer: Disable exceptions Define `JSON_NOEXCEPTION` to avoid raising exceptions. Exceptions are usually disabled for Google projects (https://google.github.io/styleguide/cppguide.html#Exceptions). Also pass `false` to the `allow_exceptions` parameter of `nlohmann::json::parse()`. Issue identified by @kuafuwang in #26. --- src/json_serializer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/json_serializer.cpp b/src/json_serializer.cpp index 16ada79..9d44dc1 100644 --- a/src/json_serializer.cpp +++ b/src/json_serializer.cpp @@ -14,6 +14,9 @@ #include "json_serializer.h" +// Disable JSON exceptions. We should be guarding against any exceptions being +// fired in this file. +#define JSON_NOEXCEPTION 1 #include namespace { @@ -45,7 +48,8 @@ namespace dap { namespace json { Deserializer::Deserializer(const std::string& str) - : json(new nlohmann::json(nlohmann::json::parse(str))), ownsJson(true) {} + : json(new nlohmann::json(nlohmann::json::parse(str, nullptr, false))), + ownsJson(true) {} Deserializer::Deserializer(const nlohmann::json* json) : json(json), ownsJson(false) {}