json: fix bug where a past the end iterator would be dereferenced (#341)

Summary:

The iterator was incremented without checking it in the JSON exporter. This caused an assertion to trigger on the last run in debug mode (weirdly no crashes). This change should fix that by checking the iterator at the increment site and not just when the loop rolls around.

Differential Revision: D49151482
This commit is contained in:
Jake Hillion 2023-09-11 09:37:19 -07:00 committed by Jake Hillion
parent 331c47705c
commit ac8ad26407

View File

@ -114,7 +114,7 @@ void Json::print(IntrospectionResult::const_iterator& it,
}
out_ << tab << "\"members\":" << space;
if ((++it)->type_path.size() > firstTypePath.size()) {
if (++it != end && it->type_path.size() > firstTypePath.size()) {
print(it, end);
} else {
out_ << "[]" << endl;