From 3c44689289f52f2c61f27f6779c47e3d8bdb9dee Mon Sep 17 00:00:00 2001 From: Kyle Xiao Date: Wed, 3 Jul 2024 15:02:33 +0800 Subject: [PATCH] chore: fix go test checkptr (#52) --- .github/workflows/pr-check.yml | 3 ++- internal/binary/decoder/skipping_emu.go | 2 +- internal/rt/stackmap.go | 11 ++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 03828a8..9c22c3a 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -42,7 +42,7 @@ jobs: # Exit with 1 when it find at least one finding. fail_on_error: true # Set staticcheck flags - staticcheck_flags: -checks=inherit,-SA1029 + staticcheck_flags: -checks=inherit,-SA1029, -ST1006 lint: runs-on: [ self-hosted, X64 ] @@ -58,3 +58,4 @@ jobs: uses: golangci/golangci-lint-action@v3 with: version: latest + only-new-issues: true diff --git a/internal/binary/decoder/skipping_emu.go b/internal/binary/decoder/skipping_emu.go index f2f44fa..4dba0fe 100644 --- a/internal/binary/decoder/skipping_emu.go +++ b/internal/binary/decoder/skipping_emu.go @@ -68,7 +68,7 @@ func stadd(s *_skipbuf_t, p *int, t defs.Tag) bool { func mvbuf(s *unsafe.Pointer, n *int, r *int, nb int) { *n = *n - nb *r = *r + nb - *s = unsafe.Pointer(uintptr(*s) + uintptr(nb)) + *s = unsafe.Add(*s, nb) } func do_skip(st *_skipbuf_t, s unsafe.Pointer, n int, t defs.Tag) (rv int) { diff --git a/internal/rt/stackmap.go b/internal/rt/stackmap.go index b9a9fff..d86bfd2 100644 --- a/internal/rt/stackmap.go +++ b/internal/rt/stackmap.go @@ -149,7 +149,16 @@ type StackMapBuilder struct { func (self *StackMapBuilder) Build() (p *StackMap) { nb := len(self.b.B) - bm := mallocgc(_StackMapSize+uintptr(nb)-1, byteType, false) + mallocsz := _StackMapSize + uintptr(nb) - 1 // (*StackMap).B occupies one byte + + // was f**k by go compiler, the code didn't pass compiler checks. + // we need one more byte to fix `checkptr: converted pointer straddles multiple allocations`, + // which caused by `p = (*StackMap)(bm)` when `bm` is shorter than the len of `StackMap`. + // can refactor this pile of crap, but I don't want to. + // It works by adding `mallocsz++` + mallocsz++ + + bm := mallocgc(mallocsz, byteType, false) /* initialize as 1 bitmap of N bits */ p = (*StackMap)(bm)