From a7338ab15ae6209dbdefb7121b9051cb8ede5fa2 Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 27 Jan 2023 12:26:27 +0000 Subject: In JSONParser::handleToken move processing for ls_colon and ls_comma into switch statement --- libqpdf/JSON.cc | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 32fe5730..20b2609a 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -1156,7 +1156,9 @@ JSONParser::handleToken() "JSON: offset " + std::to_string(offset) + ": unexpected colon"); } - break; + parser_state = ps_dict_after_colon; + lex_state = ls_top; + return; case ls_comma: if (!((parser_state == ps_dict_after_item) || @@ -1166,7 +1168,16 @@ JSONParser::handleToken() "JSON: offset " + std::to_string(offset) + ": unexpected comma"); } - break; + if (parser_state == ps_dict_after_item) { + parser_state = ps_dict_after_comma; + } else if (parser_state == ps_array_after_item) { + parser_state = ps_array_after_comma; + } else { + throw std::logic_error("JSONParser::handleToken: unexpected parser" + " state for comma"); + } + lex_state = ls_top; + return; case ls_end_array: if (!((parser_state == ps_array_begin) || @@ -1275,18 +1286,7 @@ JSONParser::handleToken() // whatever we need to do with it. parser_state_e next_state = ps_top; - if (lex_state == ls_colon) { - next_state = ps_dict_after_colon; - } else if (lex_state == ls_comma) { - if (parser_state == ps_dict_after_item) { - next_state = ps_dict_after_comma; - } else if (parser_state == ps_array_after_item) { - next_state = ps_array_after_comma; - } else { - throw std::logic_error("JSONParser::handleToken: unexpected parser" - " state for comma"); - } - } else if ((lex_state == ls_end_array) || (lex_state == ls_end_dict)) { + if ((lex_state == ls_end_array) || (lex_state == ls_end_dict)) { next_state = ps_stack.back(); ps_stack.pop_back(); auto tos = stack.back(); @@ -1348,9 +1348,6 @@ JSONParser::handleToken() throw std::logic_error( "JSONParser::handleToken: unexpected parser state"); } - } else { - throw std::logic_error( - "JSONParser::handleToken: unexpected null item in transition"); } if (reactor && item.get()) { -- cgit v1.2.3-54-g00ecf