mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
runtime: fix a panic when growing zero-width-element slices.
Fixes #4197. R=golang-dev, r CC=golang-dev https://golang.org/cl/6611056
This commit is contained in:
parent
4cc7bf326a
commit
782464aea5
|
@ -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);
|
||||
|
|
15
test/fixedbugs/bug457.go
Normal file
15
test/fixedbugs/bug457.go
Normal file
|
@ -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{}{})
|
||||
}
|
Loading…
Reference in a new issue