made _BInlineInput_::AddClause() more robust in low memory conditions

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-04-27 20:35:36 +00:00
parent 7a93cf5a82
commit 0d4fbcc8fe
3 changed files with 13 additions and 6 deletions
+2 -1
View File
@@ -4427,7 +4427,8 @@ BTextView::HandleInputMethodChanged(BMessage *message)
int32 clauseEnd; int32 clauseEnd;
while (message->FindInt32("be:clause_start", clauseCount, &clauseStart) == B_OK && while (message->FindInt32("be:clause_start", clauseCount, &clauseStart) == B_OK &&
message->FindInt32("be:clause_end", clauseCount, &clauseEnd) == B_OK) { message->FindInt32("be:clause_end", clauseCount, &clauseEnd) == B_OK) {
fInline->AddClause(clauseStart, clauseEnd); if (!fInline->AddClause(clauseStart, clauseEnd))
break;
clauseCount++; clauseCount++;
} }
@@ -153,12 +153,18 @@ _BInlineInput_::SetSelectionOffset(int32 offset)
\param start The offset into the string where the clause starts. \param start The offset into the string where the clause starts.
\param end The offset into the string where the clause finishes. \param end The offset into the string where the clause finishes.
*/ */
void bool
_BInlineInput_::AddClause(int32 start, int32 end) _BInlineInput_::AddClause(int32 start, int32 end)
{ {
fClauses = (clause *)realloc(fClauses, ++fNumClauses * sizeof(clause)); void *newData = realloc(fClauses, (fNumClauses + 1) * sizeof(clause));
fClauses[fNumClauses - 1].start = start; if (newData == NULL)
fClauses[fNumClauses - 1].end = end; return false;
fClauses = (clause *)newData;
fClauses[fNumClauses].start = start;
fClauses[fNumClauses].end = end;
fNumClauses++;
return true;
} }
@@ -34,7 +34,7 @@ public:
int32 SelectionOffset() const; int32 SelectionOffset() const;
void SetSelectionOffset(int32 offset); void SetSelectionOffset(int32 offset);
void AddClause(int32, int32); bool AddClause(int32, int32);
bool GetClause(int32 index, int32 *start, int32 *end) const; bool GetClause(int32 index, int32 *start, int32 *end) const;
int32 CountClauses() const; int32 CountClauses() const;