diff --git a/src/runtime/chan.go b/src/runtime/chan.go index 3fb0236785..712ad8cef9 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -84,7 +84,7 @@ func makechan(t *chantype, size int64) *hchan { } } else { c = new(hchan) - c.buf = newarray(elem, uintptr(size)) + c.buf = newarray(elem, int(size)) } c.elemsize = uint16(elem.size) c.elemtype = elem diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index ff59faab5d..509cab2f0f 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -246,7 +246,7 @@ func makemap(t *maptype, hint int64, h *hmap, bucket unsafe.Pointer) *hmap { // If hint is large zeroing this memory could take a while. buckets := bucket if B != 0 { - buckets = newarray(t.bucket, uintptr(1)< maxSliceCap(typ.size) { +// newarray allocates an array of n elements of type typ. +func newarray(typ *_type, n int) unsafe.Pointer { + if n < 0 || uintptr(n) > maxSliceCap(typ.size) { panic(plainError("runtime: allocation size out of range")) } - return mallocgc(typ.size*n, typ, true) + return mallocgc(typ.size*uintptr(n), typ, true) } //go:linkname reflect_unsafe_NewArray reflect.unsafe_NewArray -func reflect_unsafe_NewArray(typ *_type, n uintptr) unsafe.Pointer { +func reflect_unsafe_NewArray(typ *_type, n int) unsafe.Pointer { return newarray(typ, n) }