From 75e22fef4a69400e3cd811f802b448a2c898f013 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 17 Dec 2017 15:42:53 +0100 Subject: [PATCH] gems/vfs.h: fix end-of-data condition The 'File_content::for_each_line' method did not correctly detect the end of data for files without a trailing linebreak, thereby cutting the last character from the last line. --- repos/gems/include/gems/vfs.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/repos/gems/include/gems/vfs.h b/repos/gems/include/gems/vfs.h index ae9b3f16ed..f0971c1ad4 100644 --- a/repos/gems/include/gems/vfs.h +++ b/repos/gems/include/gems/vfs.h @@ -362,10 +362,10 @@ class Genode::File_content char const *curr_line = src; size_t curr_line_len = 0; - for (size_t n = 0; n < _size; n++) { + for (size_t n = 0; ; n++) { char const c = *src++; - bool const end_of_data = (c == 0 || n + 1 == _size); + bool const end_of_data = (c == 0 || n == _size); bool const end_of_line = (c == '\n'); if (!end_of_data && !end_of_line) { @@ -373,10 +373,11 @@ class Genode::File_content continue; } - fn(STRING(Cstring(curr_line, curr_line_len))); + if (!end_of_data || curr_line_len > 0) + fn(STRING(Cstring(curr_line, curr_line_len))); if (end_of_data) - return; + break; curr_line = src; curr_line_len = 0;