1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:18:12 +00:00

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).
This commit is contained in:
thatlittlegit 2020-02-13 22:53:45 -05:00 committed by Andreas Kling
parent f27a646bf5
commit d647749737
2 changed files with 4 additions and 3 deletions

View file

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