Properly handle RichString_extendLen when an external buffer already exists#1434
Merged
fasterit merged 1 commit intohtop-dev:mainfrom Apr 7, 2024
Merged
Conversation
fasterit
reviewed
Apr 6, 2024
| if (len > RICHSTRING_MAXLEN) { | ||
| // Copy from internal buffer to allocated string | ||
| this->chptr = xMalloc(charBytes(len + 1)); | ||
| memcpy(this->chptr, this->chstr, charBytes(this->chlen)); |
Member
There was a problem hiding this comment.
Does not ensure trailing \NUL does it?
Member
There was a problem hiding this comment.
RichString_setChar(this, len, 0); on line 38 will do this
Member
Author
There was a problem hiding this comment.
Exactly. NUL termination is handled below the conditional re-allocations in a central place.
| this->chptr = xRealloc(this->chptr, charBytes(len + 1)); | ||
| } else { | ||
| // Move string into internal buffer and free resources | ||
| memcpy(this->chstr, this->chptr, charBytes(len)); |
Member
There was a problem hiding this comment.
Does not ensure trailing \NUL does it?
Member
Author
There was a problem hiding this comment.
Handled by:
RichString_setChar(this, len, 0);below the large if statement.
cgzones
approved these changes
Apr 6, 2024
| if (len > RICHSTRING_MAXLEN) { | ||
| // Copy from internal buffer to allocated string | ||
| this->chptr = xMalloc(charBytes(len + 1)); | ||
| memcpy(this->chptr, this->chstr, charBytes(this->chlen)); |
Member
There was a problem hiding this comment.
RichString_setChar(this, len, 0); on line 38 will do this
ce444c6 to
a6306f0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The leak was found using GCC 14 and
-fanalyzer -flto: