Fix memory corruption with Array.chop and String.chop #3755
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.
Both Array.chop and String.chop violate an expectation that the memory
allocator had.
The memory allocator was written before the standard library and assumed
it would be responsible for doing "smart things" with realloc. That is,
when you ask for a realloc, perhaps you don't really need it. Perhaps
you already have enough.
This worked without issue in the standard library until
chop
came along.Chop turns a single previous object allocation into 2 and that confused
the memory allocator and could lead to it not reallocating (malloc and copy)
when safety required it. Instead it would return the same pointer it was given.
Based on how the Pony standard library ended up, with String and Array understanding
how much they allocated, we do not need that realloc behavior.
This commit removes the behavior from realloc and leaves it so that it will allows
do a malloc and copy which is what the standard library code expects it to do.