-
-
Notifications
You must be signed in to change notification settings - Fork 379
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
SA9002: panic: runtime error: index out of range [2] with length 1 #930
Labels
Comments
Can reproduce, looking into it. |
With the following modifications, the panic disappears: diff --git i/file.go w/file.go
index fe01944..d147db4 100644
--- i/file.go
+++ w/file.go
@@ -152,7 +152,8 @@ func (w *FileWriter) Rotate() (err error) {
func (w *FileWriter) rotate() (err error) {
var file *os.File
- file, err = os.OpenFile(w.fileargs(timeNow()))
+ args, flag, perm := w.fileargs(timeNow())
+ file, err = os.OpenFile(args, flag, perm)
if err != nil {
return err
}
@@ -216,7 +217,8 @@ func (w *FileWriter) rotate() (err error) {
}
func (w *FileWriter) create() (err error) {
- w.file, err = os.OpenFile(w.fileargs(timeNow()))
+ args, flag, perm := w.fileargs(timeNow())
+ w.file, err = os.OpenFile(args, flag, perm)
if err != nil {
return err
}
I tried to create a small and isolated snippet, but I failed to reproduce it. |
A simple reproducer is the following:
The bug is caused by us using indices from os.OpenFile's signature to index into the actual call's (as written in the code) arguments. The signature has 3 arguments, but the call has 1. Will fix. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code is on https://github.com/phuslu/log
Related to golangci/golangci-lint#1730 and phuslu/log#28
The text was updated successfully, but these errors were encountered: