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 segfault in Array.trim_in_place #1999

Merged
merged 1 commit into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/builtin/array.pony
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class Array[A] is Seq[A]

_size = last - offset
_alloc = _alloc - offset
_ptr = if _size > 0 then _ptr._offset(offset) else _ptr.create() end
_ptr = _ptr._offset(offset)

fun val trim(from: USize = 0, to: USize = -1): Array[A] val =>
"""
Expand Down
21 changes: 21 additions & 0 deletions packages/builtin_test/_test.pony
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ actor Main is TestList
test(_TestArraySlice)
test(_TestArrayTrim)
test(_TestArrayTrimInPlace)
test(_TestArrayTrimInPlaceWithAppend)
test(_TestArrayInsert)
test(_TestArrayValuesRewind)
test(_TestArrayFind)
Expand Down Expand Up @@ -1169,6 +1170,26 @@ class iso _TestArrayTrimInPlace is UnitTest
copy.trim_in_place(from, to)
h.assert_array_eq[U8](expected, copy)

class iso _TestArrayTrimInPlaceWithAppend is UnitTest
"""
Test trimming part of a array in place then append and trim again

Verifies we don't get a segfault similar to String and...
https://github.com/ponylang/ponyc/issues/1996
"""
fun name(): String => "builtin/Array.trim_in_place_with_append"

fun apply(h: TestHelper) =>
let a: Array[U8] = [0; 1; 2; 3; 4; 5; 6]
let big: Array[U8] val = recover val Array[U8].init(U8(1), 12_000) end
a.trim_in_place(a.size())
h.assert_array_eq[U8](Array[U8], a)
a.append(big)
a.trim_in_place(a.size())
h.assert_array_eq[U8](Array[U8], a)
a.append([as U8: 0; 10])
h.assert_array_eq[U8]([as U8: 0; 10], a)

class iso _TestArrayInsert is UnitTest
"""
Test inserting new element into array
Expand Down