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

v/checker: Warn about pointer indexing outside unsafe {} (#5918)

This commit is contained in:
Nick Treleaven
2020-07-22 18:28:53 +01:00
committed by GitHub
parent d46a89b90d
commit ee349691f9
19 changed files with 277 additions and 203 deletions

View File

@@ -147,6 +147,7 @@ pub fn (s string) cstr() byteptr {
*/
// cstring_to_vstring creates a copy of cstr and turns it into a v string
[unsafe_fn]
pub fn cstring_to_vstring(cstr byteptr) string {
return tos_clone(cstr)
}
@@ -1432,12 +1433,16 @@ pub fn (s string) filter(func fn(b byte) bool) string {
for i in 0 .. s.len {
mut b := s[i]
if func(b) {
buf[new_len] = b
unsafe {
buf[new_len] = b
}
new_len++
}
}
buf[new_len] = 0
return string(buf, new_len)
unsafe {
buf[new_len] = 0
return string(buf, new_len)
}
}
// Allows multi-line strings to be formatted in a way that removes white-space