From 80315322f3068123ab98632c55ee4bc9d7a03930 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 22 Oct 2019 15:40:51 +0700 Subject: [PATCH] runtime: simplify findObject bad pointer checking condition Factor out case s == nil, make the code cleaner and easier to read. Change-Id: I63f52e14351c0a0d20a611b1fe10fdc0d4947d96 Reviewed-on: https://go-review.googlesource.com/c/go/+/202498 Run-TryBot: Cuong Manh Le TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements Reviewed-by: Keith Randall --- src/runtime/mbitmap.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go index 30ec5f1cc9..7f9f71842d 100644 --- a/src/runtime/mbitmap.go +++ b/src/runtime/mbitmap.go @@ -361,12 +361,15 @@ func heapBitsForAddr(addr uintptr) (h heapBits) { // was found. These are used for error reporting. func findObject(p, refBase, refOff uintptr) (base uintptr, s *mspan, objIndex uintptr) { s = spanOf(p) + // If s is nil, the virtual address has never been part of the heap. + // This pointer may be to some mmap'd region, so we allow it. + if s == nil { + return + } // If p is a bad pointer, it may not be in s's bounds. - if s == nil || p < s.base() || p >= s.limit || s.state != mSpanInUse { - if s == nil || s.state == mSpanManual { - // If s is nil, the virtual address has never been part of the heap. - // This pointer may be to some mmap'd region, so we allow it. - // Pointers into stacks are also ok, the runtime manages these explicitly. + if p < s.base() || p >= s.limit || s.state != mSpanInUse { + // Pointers into stacks are also ok, the runtime manages these explicitly. + if s.state == mSpanManual { return } -- 2.50.0