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:
Adrien Destugues
2018-11-17 14:12:25 +01:00
parent 53ce162d3d
commit a4ba432352
+2 -2
View File
@@ -591,8 +591,8 @@ BStringView::_ValidatePreferredSize()
font_height fontHeight;
GetFontHeight(&fontHeight);
int32 lines = 0;
char* temp = fText;
int32 lines = 1;
char* temp = fText ? strchr(fText, '\n') : NULL;
while (temp != NULL) {
temp = strchr(temp + 1, '\n');
lines++;