有没有一个可以发现"nil pointer dereference"潜在恐慌的去短绒?



这里有一个简单的例子:

package main
import "fmt"
type A struct {
Name *string
}
type B struct {
A *A
}
func main() {
deref(&B{})
}
func deref(b *B) {
fmt.Println(*b.A.Name) // panic: nil pointer dereference
}

我正在寻找一种可以发现这种情况的解决方案。有一个";零性检验";在Jetbrains Goland,但它没有检查这个问题。

我在其他地方问了你的问题[1],得到的回答是:

检测所有CCD_ 1指针解引用是不可能的,我们通常不会容忍假阳性。这也是公平的计算成本高昂。

检测像这样琐碎的CCD_ 2指针解引用是不值得的,因为即使对代码进行了少量添加,它们也不再容易发现

我们有SA5011,它标记特定类型的潜在nil指针取消引用,尽管这没有帮助以你的例子。

  1. https://github.com/dominikh/go-tools/issues/1035

相关内容

最新更新