🎨 cleanup

This commit is contained in:
Niels Lohmann committed 2019-03-19 09:17:14 +01:00
1 parent 37a72dac48
commit b224c52376
4 files changed
+17 -33

No files matched your search

+1 -1
View File
@@ -442,7 +442,7 @@ fuzzing-stop:
# call cppcheck on the main header file # call cppcheck on the main header file
cppcheck: cppcheck:
cppcheck --enable=warning --inconclusive --force --std=c++11 $(SRCS) --error-exitcode=1 cppcheck --enable=warning --inline-suppr --inconclusive --force --std=c++11 $(SRCS) --error-exitcode=1
# compile and check with Clang Static Analyzer # compile and check with Clang Static Analyzer
clang_analyze: clang_analyze:
+6 -15
View File
@@ -262,15 +262,14 @@ class parser
m_lexer.get_token_string(), m_lexer.get_token_string(),
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'")); out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'"));
} }
else
{
if (JSON_UNLIKELY(not sax->number_float(res, m_lexer.get_string()))) if (JSON_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
{ {
return false; return false;
} }
break; break;
} }
}
case token_type::literal_false: case token_type::literal_false:
{ {
@@ -355,8 +354,7 @@ class parser
// empty stack: we reached the end of the hierarchy: done // empty stack: we reached the end of the hierarchy: done
return true; return true;
} }
else
{
if (states.back()) // array if (states.back()) // array
{ {
// comma -> next value // comma -> next value
@@ -384,14 +382,12 @@ class parser
skip_to_state_evaluation = true; skip_to_state_evaluation = true;
continue; continue;
} }
else
{
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_array, "array"))); exception_message(token_type::end_array, "array")));
} }
}
else // object else // object
{ {
// comma -> next value // comma -> next value
@@ -405,13 +401,11 @@ class parser
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key"))); exception_message(token_type::value_string, "object key")));
} }
else
{
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string()))) if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
{ {
return false; return false;
} }
}
// parse separator (:) // parse separator (:)
if (JSON_UNLIKELY(get_token() != token_type::name_separator)) if (JSON_UNLIKELY(get_token() != token_type::name_separator))
@@ -444,8 +438,7 @@ class parser
skip_to_state_evaluation = true; skip_to_state_evaluation = true;
continue; continue;
} }
else
{
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
@@ -453,8 +446,6 @@ class parser
} }
} }
} }
}
}
/// get next token from lexer /// get next token from lexer
token_type get_token() token_type get_token()
+2 -1
View File
@@ -4777,7 +4777,8 @@ class basic_json
// add element to array (move semantics) // add element to array (move semantics)
m_value.array->push_back(std::move(val)); m_value.array->push_back(std::move(val));
// invalidate object // invalidate object: mark it null so we do not call the destructor
// cppcheck-suppress accessMoved
val.m_type = value_t::null; val.m_type = value_t::null;
} }
+8 -16
View File
@@ -7276,15 +7276,14 @@ class parser
m_lexer.get_token_string(), m_lexer.get_token_string(),
out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'")); out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'"));
} }
else
{
if (JSON_UNLIKELY(not sax->number_float(res, m_lexer.get_string()))) if (JSON_UNLIKELY(not sax->number_float(res, m_lexer.get_string())))
{ {
return false; return false;
} }
break; break;
} }
}
case token_type::literal_false: case token_type::literal_false:
{ {
@@ -7369,8 +7368,7 @@ class parser
// empty stack: we reached the end of the hierarchy: done // empty stack: we reached the end of the hierarchy: done
return true; return true;
} }
else
{
if (states.back()) // array if (states.back()) // array
{ {
// comma -> next value // comma -> next value
@@ -7398,14 +7396,12 @@ class parser
skip_to_state_evaluation = true; skip_to_state_evaluation = true;
continue; continue;
} }
else
{
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::end_array, "array"))); exception_message(token_type::end_array, "array")));
} }
}
else // object else // object
{ {
// comma -> next value // comma -> next value
@@ -7419,13 +7415,11 @@ class parser
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
exception_message(token_type::value_string, "object key"))); exception_message(token_type::value_string, "object key")));
} }
else
{
if (JSON_UNLIKELY(not sax->key(m_lexer.get_string()))) if (JSON_UNLIKELY(not sax->key(m_lexer.get_string())))
{ {
return false; return false;
} }
}
// parse separator (:) // parse separator (:)
if (JSON_UNLIKELY(get_token() != token_type::name_separator)) if (JSON_UNLIKELY(get_token() != token_type::name_separator))
@@ -7458,8 +7452,7 @@ class parser
skip_to_state_evaluation = true; skip_to_state_evaluation = true;
continue; continue;
} }
else
{
return sax->parse_error(m_lexer.get_position(), return sax->parse_error(m_lexer.get_position(),
m_lexer.get_token_string(), m_lexer.get_token_string(),
parse_error::create(101, m_lexer.get_position(), parse_error::create(101, m_lexer.get_position(),
@@ -7467,8 +7460,6 @@ class parser
} }
} }
} }
}
}
/// get next token from lexer /// get next token from lexer
token_type get_token() token_type get_token()
@@ -17420,7 +17411,8 @@ class basic_json
// add element to array (move semantics) // add element to array (move semantics)
m_value.array->push_back(std::move(val)); m_value.array->push_back(std::move(val));
// invalidate object // invalidate object: mark it null so we do not call the destructor
// cppcheck-suppress accessMoved
val.m_type = value_t::null; val.m_type = value_t::null;
} }