golang/go

time: Parse panic: runtime error: index out of range

Metalnem opened this issue · 3 comments

What version of Go are you using (go version)?

go version go1.9beta2 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Metalnem/Go"
GORACE=""
GOROOT="/Users/Metalnem/sdk/go1.9beta2"
GOTOOLDIR="/Users/Metalnem/sdk/go1.9beta2/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3z/yh79t82n1fj5s0lxsjk9559m0000gn/T/go-build999022073=/tmp/go-build -gno-record-gcc-switches -fno-common"
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"

What did you do?

Run following program:

package main

import (
	"time"
)

func main() {
	time.Parse("_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT")
}

Also available here.

What did you expect to see?

The program should end silently.

What did you see instead?

The program panics:

panic: runtime error: index out of range

goroutine 1 [running]:
time.daysIn(...)
	/Users/Metalnem/sdk/go1.9beta2/src/time/time.go:1036
time.parse(0x108003a, 0x13, 0x107fe4d, 0x12, 0x10c1ec0, 0x10c3300, 0x2, 0x2, 0xc420018100, 0x34, ...)
	/Users/Metalnem/sdk/go1.9beta2/src/time/format.go:1039 +0x3616
time.Parse(0x108003a, 0x13, 0x107fe4d, 0x12, 0xc420018100, 0x0, 0x0, 0xc42003df70, 0x105f6d4)
	/Users/Metalnem/sdk/go1.9beta2/src/time/format.go:767 +0x68
main.main()
	/Users/Metalnem/Temp/main.go:8 +0x4b
exit status 2

Fails in 1.6, 1.7, 1.8, so not a new regression.

Hello, I want to make a contribution on this issue, but what the correct behaviour when month is ---?

CL https://golang.org/cl/51010 mentions this issue.