aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/runtime/slice.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2013-02-03 14:28:44 -0500
committerRuss Cox <rsc@golang.org>2013-02-03 14:28:44 -0500
commitf02067a99aaf5b78cc0969f32c37454ce82200d0 (patch)
tree2543ac83cdc69cf3ebdceb4174567649bac8061d /src/pkg/runtime/slice.c
parent46d6f3c62f9f51ac349b90b2181627d5c1ed424b (diff)
downloadgo-f02067a99aaf5b78cc0969f32c37454ce82200d0.tar.xz
cmd/gc: implement latest rules for checking make sizes
Fixes #4085. R=ken2 CC=golang-dev https://golang.org/cl/7277047
Diffstat (limited to 'src/pkg/runtime/slice.c')
-rw-r--r--src/pkg/runtime/slice.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c
index eda14f85c1..1678d5df8d 100644
--- a/src/pkg/runtime/slice.c
+++ b/src/pkg/runtime/slice.c
@@ -20,9 +20,14 @@ static void growslice1(SliceType*, Slice, intgo, Slice *);
void
runtimeĀ·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
{
- if(len < 0 || (intgo)len != len)
+ // NOTE: The len > MaxMem/elemsize check here is not strictly necessary,
+ // but it produces a 'len out of range' error instead of a 'cap out of range' error
+ // when someone does make([]T, bignumber). 'cap out of range' is true too,
+ // but since the cap is only being supplied implicitly, saying len is clearer.
+ // See issue 4085.
+ if(len < 0 || (intgo)len != len || t->elem->size > 0 && len > MaxMem / t->elem->size)
runtimeĀ·panicstring("makeslice: len out of range");
-
+
if(cap < len || (intgo)cap != cap || t->elem->size > 0 && cap > MaxMem / t->elem->size)
runtimeĀ·panicstring("makeslice: cap out of range");