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

checker: do not allow direct initialization of builtin types (s := string{})

This commit is contained in:
Alexander Medvednikov
2021-03-13 18:20:46 +03:00
parent f648e3f10d
commit 2f1810634e
6 changed files with 35 additions and 23 deletions

View File

@ -483,7 +483,7 @@ pub fn read_file_array<T>(path string) []T {
a := T{}
tsize := int(sizeof(a))
// prepare for reading, get current file size
mut fp := vfopen(path, 'rb') or { return array{} }
mut fp := vfopen(path, 'rb') or { return []T{} }
C.fseek(fp, 0, C.SEEK_END)
fsize := C.ftell(fp)
C.rewind(fp)
@ -492,11 +492,13 @@ pub fn read_file_array<T>(path string) []T {
buf := unsafe { malloc(fsize) }
C.fread(buf, fsize, 1, fp)
C.fclose(fp)
return array{
element_size: tsize
data: buf
len: len
cap: len
return unsafe {
array{
element_size: tsize
data: buf
len: len
cap: len
}
}
}