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.
This commit is contained in:
Norman Feske 2017-12-17 15:42:53 +01:00 committed by Christian Helmuth
parent 5d6f97cc1d
commit 75e22fef4a

View File

@ -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;