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

False positive when checking slice length #294

Open
QianKuang8 opened this issue Dec 1, 2024 · 0 comments
Open

False positive when checking slice length #294

QianKuang8 opened this issue Dec 1, 2024 · 0 comments

Comments

@QianKuang8
Copy link

Case 2 would cause an error in Nilaway. IMO, it looks like a false positive case.

package main

import "fmt"

func main() {
	var data []int
	// case 1: OK
	if len(data) == 1 {
		fmt.Println(data[0])
	}

	// case 2: Not OK
	length := len(data)
	if length == 1 {
		fmt.Println(data[0])
	}
}

// error: Potential nil panic detected. Observed nil flow from source to dereference point: 
// unassigned variable `data` sliced into
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