From: Rémy Oudompheng Date: Sat, 6 Oct 2012 10:05:52 +0000 (+0200) Subject: runtime: fix a panic when growing zero-width-element slices. X-Git-Tag: go1.1rc2~2242 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=782464aea540e9ebf720509ce627d192d84d92a7;p=gostls13.git runtime: fix a panic when growing zero-width-element slices. Fixes #4197. R=golang-dev, r CC=golang-dev https://golang.org/cl/6611056 --- diff --git a/src/pkg/runtime/slice.c b/src/pkg/runtime/slice.c index d2cc1684ee..b977f45824 100644 --- a/src/pkg/runtime/slice.c +++ b/src/pkg/runtime/slice.c @@ -114,7 +114,7 @@ runtime·growslice(SliceType *t, Slice old, int64 n, Slice ret) cap = old.cap + n; - if((intgo)cap != cap || cap < old.cap || cap > MaxMem / t->elem->size) + if((intgo)cap != cap || cap < old.cap || (t->elem->size > 0 && cap > MaxMem/t->elem->size)) runtime·panicstring("growslice: cap out of range"); growslice1(t, old, cap, &ret); diff --git a/test/fixedbugs/bug457.go b/test/fixedbugs/bug457.go new file mode 100644 index 0000000000..ee7048972a --- /dev/null +++ b/test/fixedbugs/bug457.go @@ -0,0 +1,15 @@ +// run + +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 4197: growing a slice of zero-width elements +// panics on a division by zero. + +package main + +func main() { + var x []struct{} + x = append(x, struct{}{}) +}