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

panic: runtime error: index out of range [-1] #7

Closed
knweiss opened this issue Aug 21, 2020 · 0 comments · Fixed by #10
Closed

panic: runtime error: index out of range [-1] #7

knweiss opened this issue Aug 21, 2020 · 0 comments · Fixed by #10
Labels
bug Something isn't working

Comments

@knweiss
Copy link

knweiss commented Aug 21, 2020

I found a testcase that causes a runtime panic in gci:

$ cat config/config_fuzz.go 
package config

import (
//      "os"
)
$ gci config
panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/daixiang0/gci/pkg/gci.(*pkg).fmt(0xc00011c0a0, 0x1, 0x1, 0x0)
        .../go/src/github.com/daixiang0/gci/pkg/gci/gci.go:130 +0xb0a
github.com/daixiang0/gci/pkg/gci.processFile(0xc000126020, 0x15, 0x51fbc0, 0xc000128008, 0xc00011c040, 0x0, 0x0)
        .../go/src/github.com/daixiang0/gci/pkg/gci/gci.go:297 +0x33a
github.com/daixiang0/gci/pkg/gci.visitFile.func1(0xc000126020, 0x15, 0x520b60, 0xc000110b60, 0x0, 0x0, 0x4aec7d, 0xc000110b60)
        .../go/src/github.com/daixiang0/gci/pkg/gci/gci.go:249 +0xb3
path/filepath.walk(0xc000126020, 0x15, 0x520b60, 0xc000110b60, 0xc000104290, 0x0, 0x0)
        .../go/go/src/path/filepath/path.go:360 +0x423
path/filepath.walk(0x7ffed58acf99, 0x6, 0x520b60, 0xc000110a90, 0xc000104290, 0x0, 0xc00010cec0)
        .../go/go/src/path/filepath/path.go:384 +0x2fe
path/filepath.Walk(0x7ffed58acf99, 0x6, 0xc000104290, 0x0, 0x0)
        .../go/go/src/path/filepath/path.go:406 +0x105
github.com/daixiang0/gci/pkg/gci.WalkDir(0x7ffed58acf99, 0x6, 0xc00011c040, 0xc0001109c0, 0x0)
        .../go/src/github.com/daixiang0/gci/pkg/gci/gci.go:256 +0x4d
main.main()
        .../go/src/github.com/daixiang0/gci/main.go:56 +0x1c5

AFAICS len(ret) is 0 in gci/pkg/gci/gci.go:

   130          if ret[len(ret)-1] == linebreak {
   131                  ret = ret[:len(ret)-1]
   132          }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants