When reading, don't add items to a vector before they are read. This avoids nullptrs in the list of fields, cards, etc. when exceptions are thrown

This commit is contained in:
Twan van Laarhoven
2020-05-22 00:25:55 +02:00
parent 749de23eb0
commit cbab6481a1
+4 -3
View File
@@ -217,9 +217,10 @@ template <typename T>
void Reader::handle(const Char* name, vector<T>& vector) {
String vectorKey = singular_form(name);
while (enterBlock(vectorKey.c_str())) {
vector.resize(vector.size() + 1);
handle_greedy(vector.back());
update_index(vector.back(), vector.size() - 1); // update index for IndexMap
T item;
handle_greedy(item);
update_index(item, vector.size()); // update index for IndexMap
vector.emplace_back(std::move(item));
exitBlock();
}
}