1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: new_array: cap should not be less than len

This commit is contained in:
Uwe Krüger
2020-05-07 22:41:41 +02:00
committed by GitHub
parent 673acdbd00
commit 722a2c71c3
2 changed files with 8 additions and 5 deletions

View File

@@ -142,10 +142,13 @@ pub fn v_calloc(n int) byteptr {
}
pub fn vcalloc(n int) byteptr {
if n <= 0 {
if n < 0 {
panic('calloc(<=0)')
} else if n == 0 {
return byteptr(0)
} else {
return C.calloc(n, 1)
}
return C.calloc(n, 1)
}
[unsafe_fn]