diff --git a/repos/os/include/os/vfs.h b/repos/os/include/os/vfs.h index 5070f68e4..094b3072f 100644 --- a/repos/os/include/os/vfs.h +++ b/repos/os/include/os/vfs.h @@ -498,8 +498,15 @@ class Genode::File_content template void xml(FN const &fn) const { - try { fn(Xml_node(_buffer.ptr, _buffer.size)); } - catch (Xml_node::Invalid_syntax) { fn(Xml_node("")); } + try { + if (_buffer.size) { + fn(Xml_node(_buffer.ptr, _buffer.size)); + return; + } + } + catch (Xml_node::Invalid_syntax) { } + + fn(Xml_node("")); } /** @@ -510,6 +517,9 @@ class Genode::File_content template void for_each_line(FN const &fn) const { + if (_buffer.size == 0) + return; + char const *src = _buffer.ptr; char const *curr_line = src; size_t curr_line_len = 0; @@ -538,9 +548,15 @@ class Genode::File_content /** * Call functor 'fn' with the data pointer and size in bytes + * + * If the buffer has a size of zero, 'fn' is not called. */ template - void bytes(FN const &fn) const { fn((char const *)_buffer.ptr, _buffer.size); } + void bytes(FN const &fn) const + { + if (_buffer.size) + fn((char const *)_buffer.ptr, _buffer.size); + } };