FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://go.googlecode.com/hg/


Description:
runtime: fix a panic when growing zero-width-element slices.

Fixes issue 4197.

Please review this at http://codereview.appspot.com/6611056/

Affected files:
M src/pkg/runtime/slice.c
A test/fixedbugs/bug457.go


Index: src/pkg/runtime/slice.c
===================================================================
--- a/src/pkg/runtime/slice.c
+++ b/src/pkg/runtime/slice.c
@@ -114,7 +114,7 @@

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);
Index: test/fixedbugs/bug457.go
===================================================================
new file mode 100644
--- /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{}{})
+}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedOct 6, '12 at 8:39a
activeOct 6, '12 at 10:06a
posts3
users2
websitegolang.org

2 users in discussion

Remyoudompheng: 2 posts R: 1 post

People

Translate

site design / logo © 2022 Grokbase