diff options
| author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2019-10-24 17:00:57 +0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2019-10-24 13:58:59 +0000 |
| commit | 05ee5065d0fa9d8dbb043f2099e11e1809de1133 (patch) | |
| tree | 51d075e7ee50c4fbc11f90a309dc1ad8bd6514f4 /src/syscall | |
| parent | be64a19d99918c843f8555aad580221207ea35bc (diff) | |
| download | go-05ee5065d0fa9d8dbb043f2099e11e1809de1133.tar.xz | |
syscall: correct comment in testGetdirentries
Correct comment about allocating big enough slice to copy result of
Getdirentries.
While at it, also convert from Dirent directly to slice of byte.
Updates #35092
Change-Id: I892de7953120622882e1561728e1e56b009a2351
Reviewed-on: https://go-review.googlesource.com/c/go/+/202880
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/syscall')
| -rw-r--r-- | src/syscall/getdirentries_test.go | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/syscall/getdirentries_test.go b/src/syscall/getdirentries_test.go index 1cbed8d4f7..2a3419c230 100644 --- a/src/syscall/getdirentries_test.go +++ b/src/syscall/getdirentries_test.go @@ -66,14 +66,10 @@ func testGetdirentries(t *testing.T, count int) { } data := buf[:n] for len(data) > 0 { - // syscall.Getdirentries's return value may be (and usually is) much - // smaller than a syscall.Dirent, which has lots of padding for - // the name at the end. The compiler's checkptr validation doesn't like - // that. So allocate direntMem that's always big enough, and use that - // when converting to *syscall.Dirent. - var direntMem [unsafe.Sizeof(syscall.Dirent{})]byte - copy(direntMem[:], data) - dirent := (*syscall.Dirent)(unsafe.Pointer(&direntMem[0])) + // If multiple Dirents are written into buf, sometimes when we reach the final one, + // we have cap(buf) < Sizeof(Dirent). So use an appropriate slice to copy from data. + var dirent syscall.Dirent + copy((*[unsafe.Sizeof(dirent)]byte)(unsafe.Pointer(&dirent))[:], data) data = data[dirent.Reclen:] name := make([]byte, dirent.Namlen) |
