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

@@ -76,8 +76,8 @@ pub fn environ() map[string]string {
C.FreeEnvironmentStringsW(estrings)
} $else {
e := &charptr(C.environ)
for i := 0; !isnil(e[i]); i++ {
eline := cstring_to_vstring(byteptr(e[i]))
for i := 0; !isnil(unsafe {e[i]}); i++ {
eline := unsafe {cstring_to_vstring(byteptr(e[i]))}
eq_index := eline.index_byte(`=`)
if eq_index > 0 {
res[eline[0..eq_index]] = eline[eq_index + 1..]

View File

@@ -120,11 +120,12 @@ pub fn read_file(path string) ?string {
fsize := C.ftell(fp)
// C.fseek(fp, 0, SEEK_SET) // same as `C.rewind(fp)` below
C.rewind(fp)
mut str := &byte(0)
unsafe { str = malloc(fsize + 1) }
C.fread(str, fsize, 1, fp)
str[fsize] = 0
return string(str,fsize)
unsafe {
mut str := malloc(fsize + 1)
C.fread(str, fsize, 1, fp)
str[fsize] = 0
return string(str,fsize)
}
}
/***************************** Utility ops ************************/

View File

@@ -52,7 +52,7 @@ fn init_os_args(argc int, argv &&byte) []string {
// mut args := []string{len:argc}
for i in 0 .. argc {
// args [i] = string(argv[i])
args << string(argv[i])
args << unsafe {string(argv[i])}
}
return args
}

View File

@@ -80,7 +80,7 @@ mut:
fn init_os_args_wide(argc int, argv &byteptr) []string {
mut args := []string{}
for i in 0..argc {
args << string_from_wide(&u16(argv[i]))
args << string_from_wide(unsafe {&u16(argv[i])})
}
return args
}