-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Array append sometimes segfaults #10011
Comments
Add fn main() {
println(fake_sort([5, 4, 6]))
}
fn fake_sort(nums []int) []int {
dump(nums)
if nums.len <= 1 {
return nums
}
mid := nums.len / 2
left := nums[..mid].clone()
right := nums[mid..].clone()
mut sorted := fake_sort(left)
println('About to merge right == $right')
sorted_right := fake_sort(right)
println('Appending $sorted << $sorted_right (this blows up)')
sorted << sorted_right
println('Successfully appended (never reached)')
return sorted
}
PS D:\Test\v\tt1> v run .
[.\\tt1.v:6] nums: [4, 5, 6]
[.\\tt1.v:6] nums: [4]
About to merge right == [5, 6]
[.\\tt1.v:6] nums: [5, 6]
[.\\tt1.v:6] nums: [5]
About to merge right == [6]
[.\\tt1.v:6] nums: [6]
Appending [5] << [6] (this blows up)
Successfully appended (never reached)
Appending [4] << [5, 6] (this blows up)
Successfully appended (never reached)
[4, 5, 6] |
May be related to this, though cloning the arrays doesn't help in this case. |
Huh, I guess I didn't add |
Sure But this segfault shall by no means happen even if the slices/views are being used illogically. V is a safe language so no segfaults in apps which do not havy any |
For sake of completeness:
|
The solution to this bug is either The reason it is not raising the error in a), is because currently V only checks if they are both simple identifiers (so |
@crthpl Adding |
My expectation as the programmer is that |
That's why V doesn't allow |
Just a side note - |
This is about |
As Alex has said elsewhere, algorithms that make lookups O(1) are actually slower than O(N) algos when N is small -- and N is usually small. |
Then V should check if N is small, and decide what algorigthm to use. |
That's true; that's what Go's std lib does when sorting slices, too. |
Fixed by #10219 ! 😄 |
V version: V 0.2.2 99a2fd7
OS: Debian GNU/Linux 9.13 (stretch) x86_64
What did you do?
What did you expect to see?
A bunch of logging followed by
What did you see instead?
A bunch of logging followed by a segfault:
The text was updated successfully, but these errors were encountered: