On 32-bits n*sizeof(r[0]) can overflow.
Or it can become 1<<32-eps, and mallocgc will "successfully"
allocate 0 pages for it, there are no checks downstream
and MHeap_Grow just does:
npage = (npage+15)&~15;
ask = npage<<PageShift;
LGTM=khr
R=golang-codereviews, khr
CC=golang-codereviews
https://golang.org/cl/
54760045
// Allocate directly from heap.
size = *sizep;
+ if(size + PageSize < size)
+ runtime·throw("out of memory");
npages = size >> PageShift;
if((size & PageMask) != 0)
npages++;
n++;
}
+ if(n > MaxMem/sizeof(r[0]))
+ runtime·throw("out of memory");
mem = runtime·roundupsize(n*sizeof(r[0]));
b.array = runtime·mallocgc(mem, 0, FlagNoScan|FlagNoZero);
b.len = n;