Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICU-22224 Fix undefine behavior in rbbi constructor #4

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions icu4c/source/common/rbbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedBreakIterator)
* tables object that is passed in as a parameter.
*/
RuleBasedBreakIterator::RuleBasedBreakIterator(RBBIDataHeader* data, UErrorCode &status)
: RuleBasedBreakIterator(status)
: RuleBasedBreakIterator(&status)
{
fData = new RBBIDataWrapper(data, status); // status checked in constructor
if (U_FAILURE(status)) {return;}
Expand Down Expand Up @@ -101,7 +101,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UBool isPhraseB
RuleBasedBreakIterator::RuleBasedBreakIterator(const uint8_t *compiledRules,
uint32_t ruleLength,
UErrorCode &status)
: RuleBasedBreakIterator(status)
: RuleBasedBreakIterator(&status)
{
if (U_FAILURE(status)) {
return;
Expand Down Expand Up @@ -139,7 +139,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(const uint8_t *compiledRules,
//
//-------------------------------------------------------------------------------
RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &status)
: RuleBasedBreakIterator(status)
: RuleBasedBreakIterator(&status)
{
fData = new RBBIDataWrapper(udm, status); // status checked in constructor
if (U_FAILURE(status)) {return;}
Expand Down Expand Up @@ -167,7 +167,7 @@ RuleBasedBreakIterator::RuleBasedBreakIterator(UDataMemory* udm, UErrorCode &sta
RuleBasedBreakIterator::RuleBasedBreakIterator( const UnicodeString &rules,
UParseError &parseError,
UErrorCode &status)
: RuleBasedBreakIterator(status)
: RuleBasedBreakIterator(&status)
{
if (U_FAILURE(status)) {return;}
RuleBasedBreakIterator *bi = (RuleBasedBreakIterator *)
Expand All @@ -189,21 +189,25 @@ RuleBasedBreakIterator::RuleBasedBreakIterator( const UnicodeString &rules,
// Used when creating a RuleBasedBreakIterator from a set
// of rules.
//-------------------------------------------------------------------------------
RuleBasedBreakIterator::RuleBasedBreakIterator() UPRV_NO_SANITIZE_UNDEFINED
: RuleBasedBreakIterator(fErrorCode)
RuleBasedBreakIterator::RuleBasedBreakIterator()
: RuleBasedBreakIterator(nullptr)
{
}

/**
* Simple Constructor with an error code.
* Handles common initialization for all other constructors.
*/
RuleBasedBreakIterator::RuleBasedBreakIterator(UErrorCode &status) {
utext_openUChars(&fText, nullptr, 0, &status);
LocalPointer<DictionaryCache> lpDictionaryCache(new DictionaryCache(this, status), status);
LocalPointer<BreakCache> lpBreakCache(new BreakCache(this, status), status);
if (U_FAILURE(status)) {
fErrorCode = status;
RuleBasedBreakIterator::RuleBasedBreakIterator(UErrorCode *status) {
UErrorCode ec = U_ZERO_ERROR;
if (status == nullptr) {
status = &ec;
}
utext_openUChars(&fText, nullptr, 0, status);
LocalPointer<DictionaryCache> lpDictionaryCache(new DictionaryCache(this, *status), *status);
LocalPointer<BreakCache> lpBreakCache(new BreakCache(this, *status), *status);
if (U_FAILURE(*status)) {
fErrorCode = *status;
return;
}
fDictionaryCache = lpDictionaryCache.orphan();
Expand Down
2 changes: 1 addition & 1 deletion icu4c/source/common/unicode/rbbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class U_COMMON_API RuleBasedBreakIterator /*U_FINAL*/ : public BreakIterator {
* Internally, handles common initialization for other constructors.
* @internal (private)
*/
RuleBasedBreakIterator(UErrorCode &status);
RuleBasedBreakIterator(UErrorCode *status);

public:

Expand Down