diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2020-07-15 18:56:39 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2020-10-23 23:01:26 +0000 |
commit | fe70866d1dc8c44ab19180ecab2b5c5b8628265a (patch) | |
tree | aec5f77935fdf60eaf9f35834f50489eabb06d38 /src/runtime/mranges.go | |
parent | e01a1c01f830e2398b773b803dce3238b1107ce9 (diff) | |
download | go-fe70866d1dc8c44ab19180ecab2b5c5b8628265a.tar.gz go-fe70866d1dc8c44ab19180ecab2b5c5b8628265a.zip |
runtime: throw on zero-sized range passed to addrRanges.add
addrRanges represents a set of addresses. Currently, passing in a
zero-sized range will cause that range to be added to the list, even
though it doesn't represent any address (addrRanges.contains will still
always return false, and findSucc will give surprising results).
We could ignore this input, but it's almost always a bug for the calling
code to pass in a zero-sized range, so just throw.
Change-Id: I8ed09e15b79a3a33e2d0cf5ed55f9e497388e7a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/242817
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/mranges.go')
-rw-r--r-- | src/runtime/mranges.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/runtime/mranges.go b/src/runtime/mranges.go index 2c0eb2c2dd..1109f506a6 100644 --- a/src/runtime/mranges.go +++ b/src/runtime/mranges.go @@ -218,7 +218,7 @@ func (a *addrRanges) contains(addr uintptr) bool { // add inserts a new address range to a. // -// r must not overlap with any address range in a. +// r must not overlap with any address range in a and r.size() must be > 0. func (a *addrRanges) add(r addrRange) { // The copies in this function are potentially expensive, but this data // structure is meant to represent the Go heap. At worst, copying this @@ -229,6 +229,12 @@ func (a *addrRanges) add(r addrRange) { // of 16) and Go heaps are usually mostly contiguous, so the chance that // an addrRanges even grows to that size is extremely low. + // An empty range has no effect on the set of addresses represented + // by a, but passing a zero-sized range is almost always a bug. + if r.size() == 0 { + print("runtime: range = {", hex(r.base.addr()), ", ", hex(r.limit.addr()), "}\n") + throw("attempted to add zero-sized address range") + } // Because we assume r is not currently represented in a, // findSucc gives us our insertion index. i := a.findSucc(r.base.addr()) |