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:
parent
e951e9fb0b
commit
099fb7b8d5
@ -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()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user