From 061067bf955cdfbbf0beba755ede512792757556 Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Mon, 12 Jul 2021 13:04:04 +0800 Subject: [PATCH] enable vet. --- .github/workflows/go.yml | 3 +++ utils/sys.go | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c7b0db0f..bfa9f6a0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -25,6 +25,9 @@ jobs: run: | go get -v -t -d ./... + - name: Vet + run: go vet -stdmethods=false ./... + - name: Build run: go build -v ./... diff --git a/utils/sys.go b/utils/sys.go index 6d383b21..f7d587da 100644 --- a/utils/sys.go +++ b/utils/sys.go @@ -13,15 +13,18 @@ type multiReadSeeker struct { multiReader io.Reader } +func add(p unsafe.Pointer, x uintptr) unsafe.Pointer { + return unsafe.Pointer(uintptr(p) + x) +} + func IsChanClosed(ch interface{}) bool { if reflect.TypeOf(ch).Kind() != reflect.Chan { panic("object is not a channel.") } - ptr := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&ch)) + unsafe.Sizeof(uint(0)))) - ptr += unsafe.Sizeof(uint(0)) * 2 - ptr += unsafe.Sizeof(uintptr(0)) - ptr += unsafe.Sizeof(uint16(0)) - return *(*uint32)(unsafe.Pointer(ptr)) > 0 + return *(*uint32)( + add(*(*unsafe.Pointer)(add(unsafe.Pointer(&ch), unsafe.Sizeof(uintptr(0)))), + unsafe.Sizeof(uint(0))*2+unsafe.Sizeof(uintptr(0))+unsafe.Sizeof(uint16(0))), + ) > 0 } func ComputeMd5AndLength(r io.Reader) ([]byte, int64) {