Merge branch 'develop' into coverity_scan

This commit is contained in:
Niels Lohmann 2017-02-01 16:03:51 +01:00
commit 7bb7033383
4 changed files with 45 additions and 17 deletions

View File

@ -563,7 +563,9 @@ namespace nlohmann {
} }
static void from_json(const json& j, boost::optional<T>& opt) { static void from_json(const json& j, boost::optional<T>& opt) {
if (!j.is_null()) { if (j.is_null()) {
opt = boost::none;
} else {
opt = j.get<T>(); // same as above, but with opt = j.get<T>(); // same as above, but with
// adl_serializer<T>::from_json // adl_serializer<T>::from_json
} }

View File

@ -3036,10 +3036,8 @@ class basic_json
{ {
return m_value.boolean; return m_value.boolean;
} }
else
{ JSON_THROW(std::domain_error("type must be boolean, but is " + type_name()));
JSON_THROW(std::domain_error("type must be boolean, but is " + type_name()));
}
} }
/// get a pointer to the value (object) /// get a pointer to the value (object)
@ -8534,10 +8532,11 @@ class basic_json
return *this; return *this;
} }
primitive_iterator_t& operator++(int) primitive_iterator_t operator++(int)
{ {
auto result = *this;
m_it++; m_it++;
return *this; return result;
} }
primitive_iterator_t& operator--() primitive_iterator_t& operator--()
@ -8546,10 +8545,11 @@ class basic_json
return *this; return *this;
} }
primitive_iterator_t& operator--(int) primitive_iterator_t operator--(int)
{ {
auto result = *this;
m_it--; m_it--;
return *this; return result;
} }
primitive_iterator_t& operator+=(difference_type n) primitive_iterator_t& operator+=(difference_type n)

View File

@ -3036,10 +3036,8 @@ class basic_json
{ {
return m_value.boolean; return m_value.boolean;
} }
else
{ JSON_THROW(std::domain_error("type must be boolean, but is " + type_name()));
JSON_THROW(std::domain_error("type must be boolean, but is " + type_name()));
}
} }
/// get a pointer to the value (object) /// get a pointer to the value (object)
@ -8534,10 +8532,11 @@ class basic_json
return *this; return *this;
} }
primitive_iterator_t& operator++(int) primitive_iterator_t operator++(int)
{ {
auto result = *this;
m_it++; m_it++;
return *this; return result;
} }
primitive_iterator_t& operator--() primitive_iterator_t& operator--()
@ -8546,10 +8545,11 @@ class basic_json
return *this; return *this;
} }
primitive_iterator_t& operator--(int) primitive_iterator_t operator--(int)
{ {
auto result = *this;
m_it--; m_it--;
return *this; return result;
} }
primitive_iterator_t& operator+=(difference_type n) primitive_iterator_t& operator+=(difference_type n)

View File

@ -596,6 +596,32 @@ TEST_CASE("parser class")
"missing or wrong low surrogate"); "missing or wrong low surrogate");
} }
SECTION("tests found by mutate++")
{
// test case to make sure no comma preceeds the first key
CHECK_THROWS_AS(json::parser("{,\"key\": false}").parse(), std::invalid_argument);
// test case to make sure an object is properly closed
CHECK_THROWS_AS(json::parser("[{\"key\": false true]").parse(), std::invalid_argument);
// test case to make sure the callback is properly evaluated after reading a key
{
json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
{
if (event == json::parse_event_t::key)
{
return false;
}
else
{
return true;
}
};
json x = json::parse("{\"key\": false}", cb);
CHECK(x == json::object());
}
}
SECTION("callback function") SECTION("callback function")
{ {
auto s_object = R"( auto s_object = R"(