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-22584 Fix derefence of nullptr #2738

Merged
merged 1 commit into from
Dec 11, 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
12 changes: 7 additions & 5 deletions icu4c/source/common/rbbinode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,20 @@ void RBBINode::NRDeleteNode(RBBINode *node) {

RBBINode *stopNode = node->fParent;
RBBINode *nextNode = node;
while (nextNode != stopNode) {
while (nextNode != stopNode && nextNode != nullptr) {
RBBINode *currentNode = nextNode;

if ((currentNode->fLeftChild == nullptr && currentNode->fRightChild == nullptr) ||
currentNode->fType == varRef || // varRef and setRef nodes do not
currentNode->fType == setRef) { // own their children nodes.
// CurrentNode is effectively a leaf node; it's safe to go ahead and delete it.
nextNode = currentNode->fParent;
if (nextNode->fLeftChild == currentNode) {
nextNode->fLeftChild = nullptr;
} else if (nextNode->fRightChild == currentNode) {
nextNode->fRightChild = nullptr;
if (nextNode) {
if (nextNode->fLeftChild == currentNode) {
nextNode->fLeftChild = nullptr;
} else if (nextNode->fRightChild == currentNode) {
nextNode->fRightChild = nullptr;
}
}
delete currentNode;
} else if (currentNode->fLeftChild) {
Expand Down
3 changes: 3 additions & 0 deletions icu4c/source/test/intltest/rbbitst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5872,6 +5872,9 @@ void RBBITest::TestBug22584() {
UErrorCode ec {U_ZERO_ERROR};

RuleBasedBreakIterator bi(ruleStr, pe, ec);
ec = U_ZERO_ERROR;
ruleStr = u"a/b;c";
RuleBasedBreakIterator bi2(ruleStr, pe, ec);
}

void RBBITest::TestBug22581() {
Expand Down
Loading