summaryrefslogtreecommitdiff
path: root/src/pkg/runtime/slice.c
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-05-01 13:15:42 -0700
committerRuss Cox <rsc@golang.org>2010-05-01 13:15:42 -0700
commit7f880650f76417b4010da786f4c82009a987d4ab (patch)
tree2ff37f89bce27884dc59c851f1d2e97977ef487d /src/pkg/runtime/slice.c
parent93076f9a25e6470ea07d6459abd122c60398a1ec (diff)
downloadgolang-7f880650f76417b4010da786f4c82009a987d4ab.tar.gz
gc: be pickier about slice, chan, array, and map sizes
Fixes issue 589. R=ken2 CC=golang-dev http://codereview.appspot.com/1032044
Diffstat (limited to 'src/pkg/runtime/slice.c')
-rw-r--r--src/pkg/runtime/slice.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c
index c3c079c67..d967b1669 100644
--- a/src/pkg/runtime/slice.c
+++ b/src/pkg/runtime/slice.c
@@ -9,17 +9,20 @@
static int32 debug = 0;
// see also unsafe·NewArray
-// makeslice(typ *Type, nel int, cap int) (ary []any);
+// makeslice(typ *Type, len, cap int64) (ary []any);
void
-·makeslice(SliceType *t, uint32 nel, uint32 cap, Slice ret)
+·makeslice(SliceType *t, int64 len, int64 cap, Slice ret)
{
- uint64 size;
+ uintptr size;
+
+ if(len < 0 || (int32)len != len)
+ panicstring("makeslice: len out of range");
+ if(cap < len || (int32)cap != cap || cap > ((uintptr)-1) / t->elem->size)
+ panicstring("makeslice: cap out of range");
- if(cap < nel)
- cap = nel;
size = cap*t->elem->size;
- ret.len = nel;
+ ret.len = len;
ret.cap = cap;
if((t->elem->kind&KindNoPointers))
@@ -30,8 +33,8 @@ void
FLUSH(&ret);
if(debug) {
- printf("makeslice(%S, %d, %d); ret=",
- *t->string, nel, cap);
+ printf("makeslice(%S, %D, %D); ret=",
+ *t->string, len, cap);
·printslice(ret);
}
}