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

checker: warn if C.m* or C.s* functions are called outside unsafe blocks (#5869)

This commit is contained in:
Nick Treleaven
2020-07-20 18:06:41 +01:00
committed by GitHub
parent 1a5236e53d
commit a74cbf55c7
23 changed files with 175 additions and 88 deletions

View File

@@ -88,7 +88,9 @@ fn fast_string_eq(a, b string) bool {
if a.len != b.len {
return false
}
return C.memcmp(a.str, b.str, b.len) == 0
unsafe {
return C.memcmp(a.str, b.str, b.len) == 0
}
}
// Dynamic array with very low growth factor
@@ -502,11 +504,13 @@ pub fn (d DenseArray) clone() DenseArray {
cap: d.cap
len: d.len
deletes: d.deletes
keys: &string(malloc(int(d.cap * sizeof(string))))
values: byteptr(malloc(int(d.cap * u32(d.value_bytes))))
keys: unsafe {&string(malloc(int(d.cap * sizeof(string))))}
values: unsafe {byteptr(malloc(int(d.cap * u32(d.value_bytes))))}
}
unsafe {
C.memcpy(res.keys, d.keys, d.cap * sizeof(string))
C.memcpy(res.values, d.values, d.cap * u32(d.value_bytes))
}
C.memcpy(res.keys, d.keys, d.cap * sizeof(string))
C.memcpy(res.values, d.values, d.cap * u32(d.value_bytes))
return res
}