summaryrefslogtreecommitdiff
path: root/libgo
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-11-28 06:48:54 -0800
committerIan Lance Taylor <iant@golang.org>2020-11-30 12:22:14 -0800
commit9ebad4b01c22d4c03a3552fd6b0e86c9de0ce6bd (patch)
treeff2741f17fb80f494bd1ce08b2b31e8605e0c90d /libgo
parente848a83f46f15280ad654f05545cc5ec4f5b8e50 (diff)
compiler, runtime: check len/cap for append(s, make(T, l)...)
The overflow checks done in growslice always reported an error for the capacity argument, even if it was the length argument that overflowed. This change lets the code pass the current issue4085b.go test. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273806
Diffstat (limited to 'libgo')
-rw-r--r--libgo/go/runtime/slice.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/libgo/go/runtime/slice.go b/libgo/go/runtime/slice.go
index 97b26594dad..ddd588ed5b9 100644
--- a/libgo/go/runtime/slice.go
+++ b/libgo/go/runtime/slice.go
@@ -15,6 +15,7 @@ import (
//go:linkname panicmakeslicelen
//go:linkname panicmakeslicecap
//go:linkname makeslice
+//go:linkname checkMakeSlice
//go:linkname makeslice64
//go:linkname growslice
//go:linkname slicecopy
@@ -91,6 +92,13 @@ func makeslicecopy(et *_type, tolen int, fromlen int, from unsafe.Pointer) unsaf
}
func makeslice(et *_type, len, cap int) unsafe.Pointer {
+ mem := checkMakeSlice(et, len, cap)
+ return mallocgc(mem, et, true)
+}
+
+// checkMakeSlice is called for append(s, make([]T, len, cap)...) to check
+// the values of len and cap.
+func checkMakeSlice(et *_type, len, cap int) uintptr {
mem, overflow := math.MulUintptr(et.size, uintptr(cap))
if overflow || mem > maxAlloc || len < 0 || len > cap {
// NOTE: Produce a 'len out of range' error instead of a
@@ -104,8 +112,7 @@ func makeslice(et *_type, len, cap int) unsafe.Pointer {
}
panicmakeslicecap()
}
-
- return mallocgc(mem, et, true)
+ return mem
}
func makeslice64(et *_type, len64, cap64 int64) unsafe.Pointer {