-
-
Notifications
You must be signed in to change notification settings - Fork 766
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-20042 Improve OOM handling in PluralRules class. #20
Conversation
icu4c/source/i18n/plurrule.cpp
Outdated
} | ||
|
||
PluralRules& | ||
PluralRules::operator=(const PluralRules& other) { | ||
if (this != &other) { | ||
delete mRules; | ||
if (other.mRules==NULL) { | ||
mRules = NULL; | ||
mInternalStatus = other.mInternalStatus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to set mRules = nullptr here, otherwise the failure case could leave it with the deleted value, and the destructor could end up deleting again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Thank you very much for the review!
This would also somewhat simplify the if statement below.
I will push an update shortly.
…r, otherwise we can end up with double deletes in the failure case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few tweaks, then it looks good.
icu4c/source/i18n/plurrule.cpp
Outdated
return NULL; | ||
LocalPointer<PluralRules> newObj(new PluralRules(status), status); | ||
if (U_FAILURE(status)) { | ||
return nullptr; | ||
} | ||
UnicodeString locRule = newObj->getRuleFromResource(locale, type, status); | ||
// TODO: which errors, if any, should be returned? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check for, and not overwrite, U_MEMORY_ALLOCATION_ERROR at this point.
Possibly only overwrite U_MISSING_RESOURCE_ERROR, but I'm not completely sure about that. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review Andy!
It now checks for U_MEMORY_ALLOCATION_ERROR
, and will stop and report it back to the caller. I didn't check for U_MISSING_RESOURCE_ERROR
. #Resolved
icu4c/source/i18n/plurrule.cpp
Outdated
AndConstraint::AndConstraint(const AndConstraint& other) { | ||
this->fInternalStatus = other.fInternalStatus; | ||
if (U_FAILURE(fInternalStatus)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to get the object fully initialized, esp. rangeList
and next
before returning, so that the destructor will not try to delete uninitialized pointers. With C++11, we could just move the initialization from the default constructor into the class declaration, using direct member initialization. Then this constructor could stay as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again Andy!
I think I will use the direct member initialization in the class declaration for this so then the default constructor can go away.
this->childNode = NULL; | ||
this->fInternalStatus = other.fInternalStatus; | ||
if (U_FAILURE(fInternalStatus)) { | ||
return; // stop early if the object we are copying from is invalid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, init pointer members before returning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you again.
…member initializers for class members to avoid dangling pointers. Also also for using default constructors too.
Setting the primary reviewer to Andy, since he has already provided lots of great feedback. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- PluralRules class doesn't handle out-of-memory (OOM) errors in some code paths. - The clone and assignment operator (operator=) methods of construction 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. - Using an internal status variable for these above cases. - Changes to the various PluralRules helper classes to check for OOM as well. - Using nullptr instead NULL. - Using LocalPointer instead of raw new/delete in some cases. - Need to set mRules to nullptr, otherwise we can end up with double deletes in the failure case. (Thanks to Andy for the review). - Using default member initializers for class members to avoid dangling pointers. Also allows for using default constructors too.
- PluralRules class doesn't handle out-of-memory (OOM) errors in some code paths. - The clone and assignment operator (operator=) methods of construction 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. - Using an internal status variable for these above cases. - Changes to the various PluralRules helper classes to check for OOM as well. - Using nullptr instead NULL. - Using LocalPointer instead of raw new/delete in some cases. - Need to set mRules to nullptr, otherwise we can end up with double deletes in the failure case. (Thanks to Andy for the review). - Using default member initializers for class members to avoid dangling pointers. Also allows for using default constructors too.
- PluralRules class doesn't handle out-of-memory (OOM) errors in some code paths. - The clone and assignment operator (operator=) methods of construction 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. - Using an internal status variable for these above cases. - Changes to the various PluralRules helper classes to check for OOM as well. - Using nullptr instead NULL. - Using LocalPointer instead of raw new/delete in some cases. - Need to set mRules to nullptr, otherwise we can end up with double deletes in the failure case. (Thanks to Andy for the review). - Using default member initializers for class members to avoid dangling pointers. Also allows for using default constructors too.
- PluralRules class doesn't handle out-of-memory (OOM) errors in some code paths. - The clone and assignment operator (operator=) methods of construction 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. - Using an internal status variable for these above cases. - Changes to the various PluralRules helper classes to check for OOM as well. - Using nullptr instead NULL. - Using LocalPointer instead of raw new/delete in some cases. - Need to set mRules to nullptr, otherwise we can end up with double deletes in the failure case. (Thanks to Andy for the review). - Using default member initializers for class members to avoid dangling pointers. Also allows for using default constructors too.
- PluralRules class doesn't handle out-of-memory (OOM) errors in some code paths. - The clone and assignment operator (operator=) methods of construction 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. - Using an internal status variable for these above cases. - Changes to the various PluralRules helper classes to check for OOM as well. - Using nullptr instead NULL. - Using LocalPointer instead of raw new/delete in some cases. - Need to set mRules to nullptr, otherwise we can end up with double deletes in the failure case. (Thanks to Andy for the review). - Using default member initializers for class members to avoid dangling pointers. Also allows for using default constructors too.
- PluralRules class doesn't handle out-of-memory (OOM) errors in some code paths. - The clone and assignment operator (operator=) methods of construction 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. - Using an internal status variable for these above cases. - Changes to the various PluralRules helper classes to check for OOM as well. - Using nullptr instead NULL. - Using LocalPointer instead of raw new/delete in some cases. - Need to set mRules to nullptr, otherwise we can end up with double deletes in the failure case. (Thanks to Andy for the review). - Using default member initializers for class members to avoid dangling pointers. Also allows for using default constructors too.
ICU-20568 Read unitsTest.txt, prepare to run unit tests.
Fix getConversionRateInfo compound-base-unit calculation bug
Test that addSingleFactorConstant knowns all unitConstants.
…t set it at build time. (unicode-org#20) When testing out the Nuget package, the value reported by the API `u_getVersion` doesn't actually match the MS-ICU version number. This is because the macro `U_ICU_VERSION` wasn't updated, only the macro `U_ICU_VERSION_BUILDLEVEL_NUM` was being updated. Initially, I was going to modify the `Set-ICUVersion.ps1` script to set this macro as well at build time. However, when testing I noticed that the `make dist` command actually takes the output from the git commit using the `git archive` command. This means that we need to actually modify and commit the version number, and not set it on the fly during the build. Instead, we'll now have to update the two macros in the `uvernum.h` file directly, but in order to make sure things don't get out of sync, I modified the `Set-ICUVersion.ps1` script to check that they match. Also in this change: I added a "clean" step to the CI pipeline to clean everything, as I noticed that if you do a force push, sometimes the contents of the build machines doesn't get cleaned properly.
Improve the handling of out-of-memory (OOM) errors in the PluralRules class. Use an internal error code to better report errors during clone and copy construction, use LocalPointer in some places to prevent memory leaks when OOM occurs, and also use nullptr instead of NULL.