Skip to content

Commit

Permalink
Handle nil when looking up a file by position into a package (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccojocar committed Dec 22, 2021
1 parent 3038a30 commit 63a8e78
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion analyzer.go
Expand Up @@ -219,7 +219,12 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
func (gosec *Analyzer) Check(pkg *packages.Package) {
gosec.logger.Println("Checking package:", pkg.Name)
for _, file := range pkg.Syntax {
checkedFile := pkg.Fset.File(file.Pos()).Name()
fp := pkg.Fset.File(file.Pos())
if fp == nil {
// skip files which cannot be located
continue
}
checkedFile := fp.Name()
// Skip the no-Go file from analysis (e.g. a Cgo files is expanded in 3 different files
// stored in the cache which do not need to by analyzed)
if filepath.Ext(checkedFile) != ".go" {
Expand Down

0 comments on commit 63a8e78

Please sign in to comment.