From 099fb7b8d557f82139405ca7d0f925690536531d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Wed, 26 Apr 2017 10:25:43 -0400 Subject: [PATCH] throw an exception instead of using assert() assert() may be compiled out in production and is clunkier to catch. some ParserException are already thrown elsewhere in the code and it seems to make sense to reuse the primitive, although it may still crash improperly configured library consumers, those who do not handle exceptions explicitly. we use the BAD_FILE error message because at this point we do not exactly know which specific data structure led to the recursion. --- src/singledocparser.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/singledocparser.cpp b/src/singledocparser.cpp index 293ba76..7bc613e 100644 --- a/src/singledocparser.cpp +++ b/src/singledocparser.cpp @@ -47,7 +47,9 @@ void SingleDocParser::HandleDocument(EventHandler& eventHandler) { } void SingleDocParser::HandleNode(EventHandler& eventHandler) { - assert(depth < depth_limit); + if (depth > depth_limit) { + throw ParserException(m_scanner.mark(), ErrorMsg::BAD_FILE); + } depth++; // an empty node *is* a possibility if (m_scanner.empty()) {