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

builtin: Fix undefined behaviour when allocating empty structs (#4088)

This commit is contained in:
radare
2020-03-21 12:24:34 +01:00
committed by GitHub
parent 7b1b647832
commit cc75fe4fe5
2 changed files with 14 additions and 2 deletions

View File

@@ -177,6 +177,9 @@ pub fn free(ptr voidptr) {
}
pub fn memdup(src voidptr, sz int) voidptr {
if sz == 0 {
return vcalloc(1)
}
mem := malloc(sz)
return C.memcpy(mem, src, sz)
}