From 7d3cd7cba5a08304eec8f193ef070a89dd3bd31e Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Mon, 11 Dec 2023 12:11:59 -0800 Subject: [PATCH] ICU-22584 Fix def of nullptr ICU-22584 fix --- icu4c/source/common/rbbinode.cpp | 12 +++++++----- icu4c/source/test/intltest/rbbitst.cpp | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/icu4c/source/common/rbbinode.cpp b/icu4c/source/common/rbbinode.cpp index a1f8b78e629..05b6efc642f 100644 --- a/icu4c/source/common/rbbinode.cpp +++ b/icu4c/source/common/rbbinode.cpp @@ -150,7 +150,7 @@ 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) || @@ -158,10 +158,12 @@ void RBBINode::NRDeleteNode(RBBINode *node) { 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) { diff --git a/icu4c/source/test/intltest/rbbitst.cpp b/icu4c/source/test/intltest/rbbitst.cpp index 16f1ea8081c..1145e332f51 100644 --- a/icu4c/source/test/intltest/rbbitst.cpp +++ b/icu4c/source/test/intltest/rbbitst.cpp @@ -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() {