1
0
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:
Nick Treleaven
2021-02-17 19:45:11 +00:00
committed by GitHub
parent 177c8bfc78
commit 4ccf991f61
7 changed files with 19 additions and 17 deletions

View File

@@ -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()
}