Commit 80315322 authored by Cuong Manh Le's avatar Cuong Manh Le Committed by Austin Clements

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 <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent d1969015
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment