golang 常见问题解析: panic: runtime error: makeslice: len out of range
https://github.com/golang/go/issues/38673
that error is triggered by the makeslice
function in the runtime, when the len
argument of make( )
called on a slice is either negative of unreasonably big; e.g:
n := -1 sl := make([]int, n) // make argument is negative
n := 1<<60 sl := make([]int, n) // make argument is too big
(make
is the function that is used to allocate an array, len
is the requested length of the array. For obvious reasons, it makes no sense to ask for a negative len, or a lenght that would make the array require thousands of terabytes of memory).
This means that the Go application you are using has a programming error and it doesn't check that a number that is passed to make
somewhere is negative or too big.
Since this is not a Go bug, but an issue in the user code that needs to be fixed in the application, I'm closing this issue. If you believe that this actually may be a bug in the Go compiler on in the runtime, please provide an autocontained code snippet that
1) is correct
2) triggers the error;
the upper limit of a slice is some significant fraction of the address space of a process. For 32 bit processes, between 1-2 gb, perhaps a little less on 32 bit windows because of DLL address space fragmentation. For 64 bit processes, in excess of a terrabyte, 10^40 bits.