Fix line counting in StringView.cpp
- if fText is an empty string, we would start searching past its end, possibly leading to a crash (noticed this in HaikuDepot). - if fText is NULL, BString would report a size of 0 lines, it makes more sense to report a size of 1 line.
This commit is contained in:
@@ -591,8 +591,8 @@ BStringView::_ValidatePreferredSize()
|
|||||||
font_height fontHeight;
|
font_height fontHeight;
|
||||||
GetFontHeight(&fontHeight);
|
GetFontHeight(&fontHeight);
|
||||||
|
|
||||||
int32 lines = 0;
|
int32 lines = 1;
|
||||||
char* temp = fText;
|
char* temp = fText ? strchr(fText, '\n') : NULL;
|
||||||
while (temp != NULL) {
|
while (temp != NULL) {
|
||||||
temp = strchr(temp + 1, '\n');
|
temp = strchr(temp + 1, '\n');
|
||||||
lines++;
|
lines++;
|
||||||
|
|||||||
Reference in New Issue
Block a user