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

Fix array and string trim_in_place allocation bounds check #2840

Merged
merged 1 commit into from
Jul 26, 2018

Commits on Jul 26, 2018

  1. Fix array and string trim_in_place allocation bounds check

    Prior to this commit, if `Array.trim_in_place` and `String.trim_in place`
    trimmed all of the memory allocated for the array or string (i.e.
    `trim_point == space()`) then trim_in_place would still use _ptr._offset
    to set the pointer to be the byte after the last byte allocated by the
    array or string. This was bad for many reasons but sometimes especially
    bad if that next byte happened to be in a different pagemap that had not
    yet been allocated. This would result in a segfault the next time `reserve`
    was called because the runtime would think this pointer was not allocated
    by pony and complain that it cannot realloc memory not allocated by pony.
    
    This commit fixes the logic in trim_in_place to allocate a new Pointer
    if _alloc == 0 (i.e. all of the memory allocated for the array or string
    has been trimmed away). This ensures that the `_ptr` will never point to
    memory not owned/allocated by the array also guaranteeing no segfaults
    will occur due to unallocated pagemap references.
    
    This commit also modifies the `Array.trim_in_place` and
    `String.trim_in_place` tests to prevent a regression.
    dipinhora committed Jul 26, 2018
    Configuration menu
    Copy the full SHA
    ec9739b View commit details
    Browse the repository at this point in the history