BView::BeginLineArray: leave object in consistent state

We allow this method to throw bad_alloc exceptions as there is no other
way to report errors. However we left the object in a broken state
(maxCount set, but array not initialized) which would crash when calling
either AddLine or EndLineArray.

Initialize the count to 0 before throwing the exception so now
EndLineArray can be called and operations resumed safely after an
allocation failure.
This commit is contained in:
Adrien Destugues 2014-11-26 12:14:36 +01:00
parent d9354cdedc
commit 31f5b8b5d2

View File

@ -3638,9 +3638,16 @@ BView::BeginLineArray(int32 count)
// calls with a NULL fCommArray would drop into the debugger anyway,
// we allow the possible std::bad_alloc exceptions here...
fCommArray = new _array_data_;
fCommArray->maxCount = count;
fCommArray->count = 0;
// Make sure the fCommArray is initialized to reasonable values in cases of
// bad_alloc. At least the exception can be caught and EndLineArray won't
// crash.
fCommArray->array = NULL;
fCommArray->maxCount = 0;
fCommArray->array = new ViewLineArrayInfo[count];
fCommArray->maxCount = count;
}