]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: simplify findObject bad pointer checking condition
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 22 Oct 2019 08:40:51 +0000 (15:40 +0700)
committerAustin Clements <austin@google.com>
Sat, 26 Oct 2019 00:05:37 +0000 (00:05 +0000)
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 <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/mbitmap.go

index 30ec5f1cc905e3dd20f3249b1bc2e5bfaec4d2e5..7f9f71842d7bcd1475b2edb48479d935ea06b116 100644 (file)
@@ -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
                }