Open
Description
Below tests cases are reporting a false positive error:
Potential nil panic detected. Observed nil flow from source to dereference point:
- line1: unassigned variable
stack
returned fromfoo()
in position 0 - line2: result 0 of
foo()
sliced into
func foo(sl []int) []*int {
if len(sl) > 0 {
var stack []*int
for _, n := range sl {
stack = append(stack, &n)
}
return stack // line1
}
return []*int{new(int)}
}
func test1() {
sl := []int{1, 2}
_ = *foo(sl)[0] // line2
}
func foo(sl []int) []*int {
switch len(sl) {
case 0:
return []*int{new(int)}
default:
var stack []*int
for _, n := range sl {
stack = append(stack, &n)
}
return stack // line1
}
}
func test2() {
sl := []int{1, 2}
_ = *foo(sl)[0] // line2
}