Skip to content

strings: Repeat: runtime error: makeslice: len out of range #25709

@bep

Description

@bep
▶ go version
go version go1.10.1 darwin/amd64
▶ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/bep/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bep/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/n6/s_85mm8d31j6yctssnmn_g1r0000gn/T/go-build040656216=/tmp/go-build -gno-record-gcc-switches -fno-common"
package main

import (
	"math"
	"strings"
)

func main() {
	strings.Repeat("h", math.MaxInt64)
}

Panics on my MacOs installation:

panic: runtime error: makeslice: len out of range

goroutine 1 [running]:
strings.Repeat(0x1071f07, 0x1, 0x7fffffffffffffff, 0xc42004bf78, 0xc42007e058)
	/usr/local/go/src/strings/strings.go:543 +0x83
main.main()

On playground it panics with a different error: https://play.golang.org/

constant 9223372036854775807 overflows int

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions