From 8304f0d136152a869ef0bd794715e1927288296c Mon Sep 17 00:00:00 2001 From: danielaparker Date: Sat, 22 Jan 2022 22:30:36 -0500 Subject: [PATCH] Improve error handling --- include/jsoncons/decode_traits.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/jsoncons/decode_traits.hpp b/include/jsoncons/decode_traits.hpp index 738865e6cf..e743c57125 100644 --- a/include/jsoncons/decode_traits.hpp +++ b/include/jsoncons/decode_traits.hpp @@ -179,6 +179,7 @@ namespace jsoncons { while (cursor.current().event_type() != staj_event_type::end_array && !ec) { v.push_back(decode_traits::decode(cursor, decoder, ec)); + if (ec) {return T{};} cursor.next(ec); } return v; @@ -419,7 +420,9 @@ namespace jsoncons { while (cursor.current().event_type() != staj_event_type::end_array && !ec) { v.insert(decode_traits::decode(cursor, decoder, ec)); + if (ec) {return T{};} cursor.next(ec); + if (ec) {return T{};} } return v; } @@ -454,7 +457,9 @@ namespace jsoncons { for (std::size_t i = 0; i < N && cursor.current().event_type() != staj_event_type::end_array && !ec; ++i) { v[i] = decode_traits::decode(cursor, decoder, ec); + if (ec) {return T{};} cursor.next(ec); + if (ec) {return T{};} } return v; } @@ -498,7 +503,9 @@ namespace jsoncons { cursor.next(ec); if (ec) return val; val.emplace(std::move(key),decode_traits::decode(cursor, decoder, ec)); + if (ec) {return val;} cursor.next(ec); + if (ec) {return val;} } return val; } @@ -547,7 +554,9 @@ namespace jsoncons { cursor.next(ec); if (ec) return val; val.emplace(n, decode_traits::decode(cursor, decoder, ec)); + if (ec) {return val;} cursor.next(ec); + if (ec) {return val;} } return val; }