-
-
Notifications
You must be signed in to change notification settings - Fork 487
Properly handle RichString_extendLen when an external buffer already exists #1434
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
Conversation
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.
Looks good otherwise
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)); |
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.
Does not ensure trailing \NUL does it?
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.
RichString_setChar(this, len, 0);
on line 38 will do this
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.
Exactly. NUL termination is handled below the conditional re-allocations in a central place.
// Just reallocate the buffer accordingly | ||
this->chptr = xRealloc(this->chptr, charBytes(len + 1)); | ||
} else { | ||
// Move string into internal buffer and free resources | ||
memcpy(this->chstr, this->chptr, charBytes(len)); |
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.
Does not ensure trailing \NUL does it?
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.
Handled by:
RichString_setChar(this, len, 0);
below the large if statement.
if (len > RICHSTRING_MAXLEN) { | ||
// Copy from internal buffer to allocated string | ||
this->chptr = xMalloc(charBytes(len + 1)); < 8000 /td> | ||
memcpy(this->chptr, this->chstr, charBytes(this->chlen)); |
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.
RichString_setChar(this, len, 0);
on line 38 will do this
ce444c6
to
a6306f0
Compare
The leak was found using GCC 14 and
-fanalyzer -flto
: