From f85ec313de2cb723b1ca004866f031635e0162e2 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 29 Nov 2019 11:38:19 +0100 Subject: [PATCH] os/vfs.h: handle zero-sized files The 'File_content' class failed to consider zero-sized files. Fixes #3557 --- repos/os/include/os/vfs.h | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/repos/os/include/os/vfs.h b/repos/os/include/os/vfs.h index 5070f68e49..094b3072fc 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); + } };