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

Simple find regexes and some regex cause golang tracebacks #1

Open
Kellel opened this issue May 19, 2017 · 1 comment
Open

Simple find regexes and some regex cause golang tracebacks #1

Kellel opened this issue May 19, 2017 · 1 comment

Comments

@Kellel
Copy link

Kellel commented May 19, 2017

A simple find with a one letter match

diff --git a/_tests/test.lua b/_tests/test.lua
index 6364aec..0ce8927 100644
--- a/_tests/test.lua
+++ b/_tests/test.lua
@@ -19,6 +19,8 @@ assert(not pcall(re.find, "aaa", "(aaaa"))
 assert(re.find("aaaa", "(b|c)*") == nil)
 a, b, s = re.find("abcd efgh ijk", "i([jk])")
 assert(a == 11 and b == 12 and s == "j")
+a, b = re.find("m", "m")
+assert(a == 1 and b == 0)

And the traceback:

kellen@chewbacca:~/.GOPATH/src/github.com/yuin/gluare$ go test
testing _tests/test.lua
--- FAIL: TestGluaRe (0.00s)
        gluare_test.go:24: runtime error: index out of range
                goroutine 18 [running]:
                github.com/yuin/gopher-lua.(*LState).PCall.func1(0xc4200a9040, 0x5f8c90, 0xc420063e40, 0x0, 0x0, 0x0)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:1631 +0x7a9
                panic(0x5bbe60, 0x6cdbb0)
                        /usr/lib/go-1.8/src/runtime/panic.go:489 +0x2cf
                github.com/yuin/gluare.reFind(0xc4200a9040, 0x1)
                        /home/kellen/.GOPATH/src/github.com/yuin/gluare/gluare.go:60 +0x59e
                github.com/yuin/gopher-lua.callGFunction(0xc4200a9040, 0x0, 0xc4200d8901)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/vm.go:123 +0x40
                github.com/yuin/gopher-lua.init.3.func26(0xc4200a9040, 0x7c180603, 0xc42012e000, 0x0)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/vm.go:699 +0x40a
                github.com/yuin/gopher-lua.mainLoop(0xc4200a9040, 0xc42012e000)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/vm.go:31 +0xd2
                github.com/yuin/gopher-lua.(*LState).callR(0xc4200a9040, 0x0, 0xffffffffffffffff, 0x0)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:876 +0x277
                github.com/yuin/gopher-lua.(*LState).Call(0xc4200a9040, 0x0, 0xffffffffffffffff)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:1610 +0x48
                github.com/yuin/gopher-lua.(*LState).PCall(0xc4200a9040, 0x0, 0xffffffffffffffff, 0x0, 0x6b85e0, 0xc420165000)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:1671 +0x116
                github.com/yuin/gopher-lua.(*LState).DoFile(0xc4200a9040, 0x5ee248, 0x8, 0x5f8708, 0x2)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/auxlib.go:394 +0xd1
                github.com/yuin/gluare.testScriptDir(0xc420090680, 0xc420063f88, 0x1, 0x1, 0x5ed91f, 0x6)
                        /home/kellen/.GOPATH/src/github.com/yuin/gluare/gluare_test.go:23 +0x2ea
                github.com/yuin/gluare.TestGluaRe(0xc420090680)
                        /home/kellen/.GOPATH/src/github.com/yuin/gluare/gluare_test.go:31 +0x74
                testing.tRunner(0xc420090680, 0x5f8710)
                        /usr/lib/go-1.8/src/testing/testing.go:657 +0x96
                created by testing.(*T).Run
                        /usr/lib/go-1.8/src/testing/testing.go:697 +0x2ca

                stack traceback:
                        [G]: in function 'find'
                        test.lua:22: in main chunk
                        [G]: ?
FAIL
exit status 1
FAIL    github.com/yuin/gluare  0.004s

And an issue with match:

@@ -65,3 +67,5 @@ assert(re.match("hello world", "\\w+", 6) == "world")
 assert(re.match("hello world", "\\w+", -5) == "world")
 a, b = re.match("from=world", "(\\w+)=(\\w+)")
 assert(a == "from" and b == "world")
+a, b, c = re.match("123ab123", "([0-9]+)([a-z]+)([0-9]+)|(bc)([0-9]+)")
+assert (a == "123" and b == "ab" and c == "123")
kellen@chewbacca:~/.GOPATH/src/github.com/yuin/gluare$ go test
testing _tests/test.lua
--- FAIL: TestGluaRe (0.00s)
        gluare_test.go:24: runtime error: slice bounds out of range
                goroutine 5 [running]:
                github.com/yuin/gopher-lua.(*LState).PCall.func1(0xc42008b040, 0x5f8c90, 0xc420063e40, 0x0, 0x0, 0x0)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:1631 +0x7a9
                panic(0x5bbe60, 0x6cdbc0)
                        /usr/lib/go-1.8/src/runtime/panic.go:489 +0x2cf
                github.com/yuin/gluare.reMatch(0xc42008b040, 0x1)
                        /home/kellen/.GOPATH/src/github.com/yuin/gluare/gluare.go:260 +0x2e9
                github.com/yuin/gopher-lua.callGFunction(0xc42008b040, 0x0, 0x1)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/vm.go:123 +0x40
                github.com/yuin/gopher-lua.init.3.func26(0xc42008b040, 0x7c180803, 0xc42010a000, 0x0)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/vm.go:699 +0x40a
                github.com/yuin/gopher-lua.mainLoop(0xc42008b040, 0xc42010a000)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/vm.go:31 +0xd2
                github.com/yuin/gopher-lua.(*LState).callR(0xc42008b040, 0x0, 0xffffffffffffffff, 0x0)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:876 +0x277
                github.com/yuin/gopher-lua.(*LState).Call(0xc42008b040, 0x0, 0xffffffffffffffff)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:1610 +0x48
                github.com/yuin/gopher-lua.(*LState).PCall(0xc42008b040, 0x0, 0xffffffffffffffff, 0x0, 0x6b85e0, 0xc42013f800)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/state.go:1671 +0x116
                github.com/yuin/gopher-lua.(*LState).DoFile(0xc42008b040, 0x5ee248, 0x8, 0x5f8708, 0x2)
                        /home/kellen/.GOPATH/src/github.com/yuin/gopher-lua/auxlib.go:394 +0xd1
                github.com/yuin/gluare.testScriptDir(0xc42006cc30, 0xc420063f88, 0x1, 0x1, 0x5ed91f, 0x6)
                        /home/kellen/.GOPATH/src/github.com/yuin/gluare/gluare_test.go:23 +0x2ea
                github.com/yuin/gluare.TestGluaRe(0xc42006cc30)
                        /home/kellen/.GOPATH/src/github.com/yuin/gluare/gluare_test.go:31 +0x74
                testing.tRunner(0xc42006cc30, 0x5f8710)
                        /usr/lib/go-1.8/src/testing/testing.go:657 +0x96
                created by testing.(*T).Run
                        /usr/lib/go-1.8/src/testing/testing.go:697 +0x2ca

                stack traceback:
                        [G]: in function 'match'
                        test.lua:70: in main chunk
                        [G]: ?
FAIL
exit status 1
FAIL    github.com/yuin/gluare  0.003s
@Kellel Kellel changed the title Many regexes cause golang tracebacks Simple find regexes and some regex cause golang tracebacks May 19, 2017
@Kellel
Copy link
Author

Kellel commented May 19, 2017

I moved a slightly different version of this regex from some go code into lua.

Kellel pushed a commit to Kellel/gluare that referenced this issue May 19, 2017
Fix find by fixing the incorrect value in nil case
Re-write match to skip messy index logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant