mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: warn when casting a fixed array (use &arr[0] instead) (#8787)
This commit is contained in:
@@ -93,8 +93,8 @@ pub fn ls(path string) ?[]string {
|
||||
if isnil(ent) {
|
||||
break
|
||||
}
|
||||
bptr := byteptr(ent.d_name)
|
||||
unsafe {
|
||||
bptr := byteptr(&ent.d_name[0])
|
||||
if bptr[0] == 0 || (bptr[0] == `.` && bptr[1] == 0)
|
||||
|| (bptr[0] == `.` && bptr[1] == `.` && bptr[2] == 0) {
|
||||
continue
|
||||
@@ -169,8 +169,8 @@ pub fn exec(cmd string) ?Result {
|
||||
buf := [4096]byte{}
|
||||
mut res := strings.new_builder(1024)
|
||||
unsafe {
|
||||
for C.fgets(charptr(buf), 4096, f) != 0 {
|
||||
bufbp := byteptr(buf)
|
||||
bufbp := &buf[0]
|
||||
for C.fgets(charptr(bufbp), 4096, f) != 0 {
|
||||
res.write_bytes(bufbp, vstrlen(bufbp))
|
||||
}
|
||||
}
|
||||
@@ -210,11 +210,11 @@ pub fn (mut c Command) read_line() string {
|
||||
buf := [4096]byte{}
|
||||
mut res := strings.new_builder(1024)
|
||||
unsafe {
|
||||
for C.fgets(charptr(buf), 4096, c.f) != 0 {
|
||||
bufbp := byteptr(buf)
|
||||
bufbp := &buf[0]
|
||||
for C.fgets(charptr(bufbp), 4096, c.f) != 0 {
|
||||
len := vstrlen(bufbp)
|
||||
for i in 0 .. len {
|
||||
if int(bufbp[i]) == `\n` {
|
||||
if bufbp[i] == `\n` {
|
||||
res.write_bytes(bufbp, i)
|
||||
return res.str()
|
||||
}
|
||||
|
||||
@@ -102,12 +102,12 @@ pub fn ls(path string) ?[]string {
|
||||
// NOTE:TODO: once we have a way to convert utf16 wide character to utf8
|
||||
// we should use FindFirstFileW and FindNextFileW
|
||||
h_find_files := C.FindFirstFile(path_files.to_wide(), voidptr(&find_file_data))
|
||||
first_filename := unsafe { string_from_wide(&u16(find_file_data.c_file_name)) }
|
||||
first_filename := unsafe { string_from_wide(&find_file_data.c_file_name[0]) }
|
||||
if first_filename != '.' && first_filename != '..' {
|
||||
dir_files << first_filename
|
||||
}
|
||||
for C.FindNextFile(h_find_files, voidptr(&find_file_data)) > 0 {
|
||||
filename := unsafe { string_from_wide(&u16(find_file_data.c_file_name)) }
|
||||
filename := unsafe { string_from_wide(&find_file_data.c_file_name[0]) }
|
||||
if filename != '.' && filename != '..' {
|
||||
dir_files << filename.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user