BTextView: Don't crash if the file supplied is zero-length.

Fixes #12551.
This commit is contained in:
Augustin Cavalier 2015-12-31 20:54:27 -05:00
parent aa89e2de03
commit 3c85734188
3 changed files with 9 additions and 6 deletions

View File

@ -1098,13 +1098,14 @@ BTextView::SetText(BFile* file, int32 offset, int32 length,
_CancelInputMethod();
if (!file)
if (file == NULL)
return;
if (fText->Length() > 0)
DeleteText(0, fText->Length());
fText->InsertText(file, offset, length, 0);
if (!fText->InsertText(file, offset, length, 0))
return;
// update the start offsets of each line below offset
fLines->BumpOffset(length, _LineAt(offset) + 1);

View File

@ -72,7 +72,7 @@ TextGapBuffer::InsertText(const char* inText, int32 inNumItems, int32 inAtIndex)
}
void
bool
TextGapBuffer::InsertText(BFile* file, int32 fileOffset, int32 inNumItems,
int32 inAtIndex)
{
@ -80,7 +80,7 @@ TextGapBuffer::InsertText(BFile* file, int32 fileOffset, int32 inNumItems,
if (file->GetSize(&fileSize) != B_OK
|| !file->IsReadable())
return;
return false;
// Clamp the text length to the file size
fileSize -= fileOffset;
@ -89,7 +89,7 @@ TextGapBuffer::InsertText(BFile* file, int32 fileOffset, int32 inNumItems,
inNumItems = fileSize;
if (inNumItems < 1)
return;
return false;
inAtIndex = (inAtIndex > fItemCount) ? fItemCount : inAtIndex;
inAtIndex = (inAtIndex < 0) ? 0 : inAtIndex;
@ -106,6 +106,8 @@ TextGapBuffer::InsertText(BFile* file, int32 fileOffset, int32 inNumItems,
fGapIndex += inNumItems;
fItemCount += inNumItems;
}
return true;
}

View File

@ -26,7 +26,7 @@ public:
void InsertText(const char* inText, int32 inNumItems,
int32 inAtIndex);
void InsertText(BFile* file, int32 fileOffset,
bool InsertText(BFile* file, int32 fileOffset,
int32 amount, int32 atIndex);
void RemoveRange(int32 start, int32 end);