Skip to content

Commit

Permalink
chore: fix go test checkptr (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaost authored Jul 3, 2024
1 parent c089f8b commit 3c44689
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand All @@ -58,3 +58,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest
only-new-issues: true
2 changes: 1 addition & 1 deletion internal/binary/decoder/skipping_emu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion internal/rt/stackmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3c44689

Please sign in to comment.