diff options
author | thatlittlegit <personal@thatlittlegit.tk> | 2020-02-13 22:53:45 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-15 20:46:10 +0100 |
commit | d647749737034796afcfc4637f310e60ec59f4b3 (patch) | |
tree | 812302b79ace6aff681f31e9c385ec6171de87ed /Applications | |
parent | f27a646bf5ecb6d0c4edc74627eacd2b19f82d2e (diff) | |
download | serenity-d647749737034796afcfc4637f310e60ec59f4b3.zip |
Welcome: Remove crash and ensure text doesn't all stay on one line.
When size_t replaced int (6f4c370), it caused the 'start = -1' trick to
fail, setting start to (unsigned)-1 instead. This then caused
String.substring to fail, as that is a little bit higher than the length
of the string! This resulted in an outright crash.
Later, the builder is not reset before making a new line. This causes
the line to simply be the earlier one, but with more text on it.
(There's also a few changes from clang-format, namely the #include
reorganization.)
Fixes #1211 (although I wasn't aware of it when I made this commit).
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/Welcome/TextWidget.cpp | 5 | ||||
-rw-r--r-- | Applications/Welcome/TextWidget.h | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/Applications/Welcome/TextWidget.cpp b/Applications/Welcome/TextWidget.cpp index 070801f4c6..c035ae2de6 100644 --- a/Applications/Welcome/TextWidget.cpp +++ b/Applications/Welcome/TextWidget.cpp @@ -100,13 +100,13 @@ void TextWidget::wrap_and_set_height() if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n') { if (start.has_value()) words.append(m_text.substring(start.value(), i - start.value())); - start = -1; + start.clear(); } else if (!start.has_value()) { start = i; } } if (start.has_value()) - words.append(m_text.substring(start, m_text.length() - start.value())); + words.append(m_text.substring(start.value(), m_text.length() - start.value())); auto rect = frame_inner_rect(); if (frame_thickness() > 0) @@ -122,6 +122,7 @@ void TextWidget::wrap_and_set_height() if (line_width + word_width > rect.width()) { lines.append(builder.to_string()); + builder.clear(); line_width = 0; } diff --git a/Applications/Welcome/TextWidget.h b/Applications/Welcome/TextWidget.h index b237c5ee35..f4c71e8cd5 100644 --- a/Applications/Welcome/TextWidget.h +++ b/Applications/Welcome/TextWidget.h @@ -28,8 +28,8 @@ #include <AK/String.h> #include <AK/Vector.h> -#include <LibGfx/TextAlignment.h> #include <LibGUI/Frame.h> +#include <LibGfx/TextAlignment.h> class TextWidget : public GUI::Frame { C_OBJECT(TextWidget) |