mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
e01a1c01f8
commit
fe70866d1d
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in New Issue