base: never throw in Xml_node::for_each_sub_node

Fixes #3231
This commit is contained in:
Norman Feske
2019-03-14 16:31:11 +01:00
committed by Christian Helmuth
parent d75c5f6722
commit 9438caa6a3
3 changed files with 18 additions and 7 deletions

View File

@ -891,15 +891,17 @@ class Genode::Xml_node
if (_num_sub_nodes == 0) if (_num_sub_nodes == 0)
return; return;
Xml_node node = sub_node(); try {
for (int i = 0; ; node = node.next()) { Xml_node node = sub_node();
for (int i = 0; ; node = node.next()) {
if (!type || node.has_type(type)) if (!type || node.has_type(type))
fn(node); fn(node);
if (++i == _num_sub_nodes) if (++i == _num_sub_nodes)
break; break;
} }
} catch (Nonexistent_sub_node) { }
} }
/** /**

View File

@ -103,6 +103,8 @@
[init -> test-xml_node] step 4 [init -> test-xml_node] step 4
[init -> test-xml_node] step 5 [init -> test-xml_node] step 5
[init -> test-xml_node] [init -> test-xml_node]
[init -> test-xml_node] -- Test iterating over invalid node --
[init -> test-xml_node]
[init -> test-xml_node] --- End of XML-parser test ---* [init -> test-xml_node] --- End of XML-parser test ---*
[init] child "test-xml_node" exited with exit value 0 [init] child "test-xml_node" exited with exit value 0
</log> </log>

View File

@ -413,6 +413,13 @@ void Component::construct(Genode::Env &env)
test_decoded_content<0 >(env, 5, xml_test_comments, 8, 119); test_decoded_content<0 >(env, 5, xml_test_comments, 8, 119);
log(""); log("");
log("-- Test iterating over invalid node --");
{
/* this must not raise a 'Nonexistent_sub_node' exception */
Xml_node("<a><b></c></a>").for_each_sub_node("c", [&] (Xml_node) { });
}
log("");
log("--- End of XML-parser test ---"); log("--- End of XML-parser test ---");
env.parent().exit(0); env.parent().exit(0);
} }