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
d540476e31
commit
ac00ef9377
@ -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()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user