You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What does 'go version' print?
go version 1.2.1 windows/amd64
What steps reproduce the problem?
Run this minimal program:
package main
import "fmt"
func main() {
length := (1 << 63) - 1
a := make([]struct{}, length/(1<<32))
b := make([]struct{}, length/(1<<32))
a = append(a, b...)
fmt.Println(len(a), cap(a))
}
Note that this *cannot* be reproduced on the Playground. Even if you substitute the
value of length with the 32-bit MaxInt (since the Playground seems to use a size of 4
instead of 8 for ints), you'll correctly get a panic from this operation.
What happened?
It will print -2 7638104968020361214 (that is, the slice has len -2 and cap
7638104968020361214).
What should have happened instead?
Probably a panic of some sort.
Please provide any additional information below.
This seems to only happen with slices of type struct{}. I tried to reproduce the error
with a []int, and it always panicked in some way. One other odd node, if instead of doing
a = append(a,b...)
you do
a = append(a,struct{}{})
It will correctly panic with the error:
panic: runtime error: runtime: allocation size out of range
One confusing thing is that the panic the Playground gives for these operations is:
panic: runtime error: growslice: cap out of range
So that may be an additional bug, or may be expected.
The text was updated successfully, but these errors were encountered:
Oops, sorry, I copied a modification of the program, the lines should be
length := (1 << 63) - 1
a := make([]struct{}, length)
b := make([]struct{}, length)
a = append(a, b...)
fmt.Println(len(a), cap(a))
The division was when I was trying to check it with a []int
For clarity, for this program:
package main
import "fmt"
func main() {
length := (1 << 63) - 1
a := make([]struct{}, length)
b := make([]struct{}, length)
a = append(a, b...)
fmt.Println(len(a), cap(a))
}
"go run" prints "-2 -2". When built with gccgo, it crashes with a "append: slice
overflow" panic.
The text was updated successfully, but these errors were encountered: