-
Notifications
You must be signed in to change notification settings - Fork 102
Simplify realloc logic #175
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 overall, but I do wonder about a possible exploit of multiple realloc()
calls given the limitations of the delta
approach - see comment
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.
Using zero initialization to both avoid length assignment and make the logic simpler is really smart :)
The base branch was changed.
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.
The change looks good to me!
There is an edge case if someone calls close()
and then resize()
within the same instruction.
With the current code, resize()
would incorrectly return an error for going over the limit, even if the account previously had some space.
How about setting the difference during close()
? close_unchecked()
can stay as it is, but it would be good to add a comment saying to avoid resizing afterwards.
7902606
to
7da489a
Compare
Good point! Fixed |
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 great to me!
Problem
The current way that
realloc
tracks the original data length is unnecessarily complex.Solution
This PR simplifies the logic on
realloc
to store difference between the original data length and the current length.