util/list_model.h: graceful handling of duplicates

This patch makes the 'List_model' utility robust against duplicated
occurrences of node IDs in the supplied XML data. If two or more XML
nodes correspond to the same model element, the existing element is
updated with the information of the subsequent XML nodes.
This commit is contained in:
Norman Feske 2018-05-09 19:01:43 +02:00 committed by Christian Helmuth
parent bf52f73d03
commit 24e6b677bd

View File

@ -135,6 +135,16 @@ void Genode::List_model<ELEM>::update_from_xml(POLICY &policy, Xml_node node)
if (!policy.node_is_element(sub_node))
return;
/* check for duplicates, which must not exist in the list model */
for (Element *dup = updated_list.first(); dup; dup = dup->_next()) {
/* update existing element with information from later node */
if (policy.element_matches_xml_node(*dup, sub_node)) {
policy.update_element(*dup, sub_node);
return;
}
}
/* look up corresponding element in original list */
Element *curr = _elements.first();
while (curr && !policy.element_matches_xml_node(*curr, sub_node))