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-20042 Improve OOM handling in PluralRules class. #20

Merged
merged 6 commits into from
Aug 2, 2018

Conversation

jefgen
Copy link
Member

@jefgen jefgen commented Jul 24, 2018

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.

@jefgen jefgen changed the title ICU-20044 Improve OOM handling in NumberFormat class. ICU-20042 Improve OOM handling in PluralRules class. Jul 24, 2018
}

PluralRules&
PluralRules::operator=(const PluralRules& other) {
if (this != &other) {
delete mRules;
if (other.mRules==NULL) {
mRules = NULL;
mInternalStatus = other.mInternalStatus;
Copy link
Contributor

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.

Copy link
Member Author

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.
Copy link
Contributor

@aheninger aheninger left a 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.

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?
Copy link
Contributor

@aheninger aheninger Jul 31, 2018

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

Copy link
Member Author

@jefgen jefgen Aug 1, 2018

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

AndConstraint::AndConstraint(const AndConstraint& other) {
this->fInternalStatus = other.fInternalStatus;
if (U_FAILURE(fInternalStatus)) {
Copy link
Contributor

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.

Copy link
Member Author

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.
Copy link
Contributor

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.

Copy link
Member Author

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.
@sffc sffc removed their request for review August 1, 2018 20:33
@jefgen
Copy link
Member Author

jefgen commented Aug 1, 2018

Setting the primary reviewer to Andy, since he has already provided lots of great feedback.

Copy link
Contributor

@aheninger aheninger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jefgen jefgen merged commit cffde97 into unicode-org:master Aug 2, 2018
@jefgen jefgen deleted the jefgen/20042 branch August 2, 2018 06:33
sffc referenced this pull request in sffc/icu Sep 26, 2018
- 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.
sffc referenced this pull request in sffc/icu Sep 26, 2018
- 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.
sffc referenced this pull request in sffc/icu Sep 27, 2018
- 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.
sffc referenced this pull request in sffc/icu Sep 27, 2018
- 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.
sffc referenced this pull request in sffc/icu Sep 27, 2018
- 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.
sffc referenced this pull request in sffc/icu Sep 27, 2018
- 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.
hugovdm pushed a commit to hugovdm/icu that referenced this pull request Mar 6, 2020
ICU-20568 Read unitsTest.txt, prepare to run unit tests.
hugovdm pushed a commit to hugovdm/icu that referenced this pull request Mar 27, 2020
Fix getConversionRateInfo compound-base-unit calculation bug
hugovdm added a commit to hugovdm/icu that referenced this pull request Jul 21, 2020
Test that addSingleFactorConstant knowns all unitConstants.
ctrlaltf24 pushed a commit to FaithLife-Community/icu that referenced this pull request Oct 23, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants