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.
This commit is contained in:
Antoine Beaupré 2017-04-26 10:25:43 -04:00
parent d540476e31
commit ac00ef9377
No known key found for this signature in database
GPG Key ID: 792152527B75921E

View File

@ -46,7 +46,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()) {