Commit 26397f13 authored by Russ Cox's avatar Russ Cox

runtime: fix upper bound on out-of-memory print

It's possible for arena_start+MaxArena32 to wrap.
We do the right thing in the bounds check but not in the print.

For #13992 (to fix the print there, not the bug).

Change-Id: I4df845d0c03f0f35461b128e4f6765d3ccb71c6d
Reviewed-on: https://go-review.googlesource.com/18975
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
parent d9fdbf48
......@@ -455,7 +455,11 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer {
}
if p < h.arena_start || uintptr(p)+p_size-h.arena_start >= _MaxArena32 {
print("runtime: memory allocated by OS (", hex(p), ") not in usable range [", hex(h.arena_start), ",", hex(h.arena_start+_MaxArena32), ")\n")
top := ^uintptr(0)
if top-h.arena_start > _MaxArena32 {
top = h.arena_start + _MaxArena32
}
print("runtime: memory allocated by OS (", hex(p), ") not in usable range [", hex(h.arena_start), ",", hex(top), ")\n")
sysFree(unsafe.Pointer(p), p_size, &memstats.heap_sys)
return nil
}
......
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