We're updating the issue view to help you get more done. 

ICU4C: UnicodeSet constructor and assignment operator should setToBogus when OOM occurs

Description

Some of the UnicodeSet constructors methods don't take an error code parameter, meaning that if an OOM error occurs during the constructor, it will not reported back to the caller, and the caller has no way to know that the object is in a half-constructed state.

Similar with the assignment operator (operator=), if OOM occurs then there is no way to know that the object that was supposed to be assigned to is now in bad state.

Note: There is already precedent for marking the set as bogus when OOM happens. For example, in the constructor below, if uprv_malloc fails then it marks the set as "bogus".

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /** * Constructs an empty set. */ UnicodeSet::UnicodeSet() : len(1), capacity(1 + START_EXTRA), list(0), bmpSet(0), buffer(0), bufferCapacity(0), patLen(0), pat(NULL), strings(NULL), stringSpan(NULL), fFlags(0) { UErrorCode status = U_ZERO_ERROR; allocateStrings(status); if (U_FAILURE(status)) { return; } list = (UChar32*) uprv_malloc(sizeof(UChar32) * capacity); if(list!=NULL){ list[0] = UNICODESET_HIGH; } else { // If memory allocation failed, set to bogus state. setToBogus(); return; } _dbgct(this); }

Status

Assignee

Jeff Genovy

Reporter

Jeff Genovy

Labels

Reviewer

Steven R. Loomis

Time Needed

None

Start date

None

Components

Fix versions

Priority

medium