summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2020-12-12 22:15:41 +0000
committerAndreas Kling <kling@serenityos.org>2020-12-13 11:00:11 +0100
commitf7bd6e2b34329082ccc4d3a8ad90bece4cb3ac6e (patch)
treeed908f70bd9ce6565e9554e30d58a917d8163a9a /Applications
parent94c56d16b372b92db05f56d62cb257f50667c6e7 (diff)
downloadserenity-f7bd6e2b34329082ccc4d3a8ad90bece4cb3ac6e.zip
Welcome: Fix reading of welcome.txt file
The buffer returned by read_line() used to be null-terminated, however that was changed in 129a58a, resulting in some line strings containing garbage data. Explicitly telling the String constructor the buffer's size fixes that. Fixes #4397.
Diffstat (limited to 'Applications')
-rw-r--r--Applications/Welcome/main.cpp18
1 files changed, 3 insertions, 15 deletions
diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp
index a754d4579a..9b120e94d5 100644
--- a/Applications/Welcome/main.cpp
+++ b/Applications/Welcome/main.cpp
@@ -55,28 +55,17 @@ struct ContentPage {
static Optional<Vector<ContentPage>> parse_welcome_file(const String& path)
{
- const auto error = Optional<Vector<ContentPage>>();
auto file = Core::File::construct(path);
-
if (!file->open(Core::IODevice::ReadOnly))
- return error;
+ return {};
Vector<ContentPage> pages;
StringBuilder current_output_line;
bool started = false;
ContentPage current;
- while (true) {
+ while (file->can_read_line()) {
auto buffer = file->read_line(4096);
- if (buffer.is_null()) {
- if (file->error()) {
- file->close();
- return error;
- }
-
- break;
- }
-
- auto line = String((char*)buffer.data());
+ auto line = String((const char*)buffer.data(), buffer.size());
if (line.length() > 1)
line = line.substring(0, line.length() - 1); // remove newline
switch (line[0]) {
@@ -122,7 +111,6 @@ static Optional<Vector<ContentPage>> parse_welcome_file(const String& path)
pages.append(current);
}
- file->close();
return pages;
}