Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex Windows panic MustCompile/MatchString #28765

Closed
rvjc opened this issue Nov 13, 2018 · 3 comments

Comments

@rvjc
Copy link

@rvjc rvjc commented Nov 13, 2018

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

go version go1.11.2 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\sys\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Sys\User\Go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\sys\AppData\Local\Temp\2\go-build287238718=/tmp/go-build -gno-record-gcc-switches

What did you do?

package main

import "fmt"
import "regexp"

var IsLetter = regexp.MustCompile(`^[a-zA-Z]+$`).MatchString

func main() {

    b := IsLetter("abc")
    fmt.Println(b)
}

What did you expect to see?

Works on playground:

true

What did you see instead?

On Windows:

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
main.main()
      .../main.go:7 +0xbc
@mvdan

This comment has been minimized.

Copy link
Member

@mvdan mvdan commented Nov 13, 2018

In the file you posted, line 7 is an empty line. The program also seems to run fine on Linux.

@viswesr

This comment has been minimized.

Copy link
Contributor

@viswesr viswesr commented Nov 13, 2018

The above program works fine on Windows as well. Built with go1.11.2 windows/amd64.

@rvjc

This comment has been minimized.

Copy link
Author

@rvjc rvjc commented Nov 13, 2018

I must be going crazy.
I'm pretty sure I double-checked before issuing bug report.

But now I copied and pasted code and it ran successfully.

A possible explanation for original panic:

The original test code was pasted from the web and modified
It's possible there were some unruly characters lingering in the file.
This might explain the "empty line 7" which @mvdan spotted.

Anyway, all is good now.
Sincere apologies for inconveniencing you and thanks for assistance

@rvjc rvjc closed this Nov 13, 2018
@golang golang locked and limited conversation to collaborators Nov 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.