mirror of
https://github.com/golang/go
synced 2024-11-18 08:54:45 -07:00
x/tools/refactor/rename: fix nil pointer dereference.
Fix a nil pointer dereference by checking the error returned by conf.Load. Bug was reported on Reddit: https://www.reddit.com/r/golang/comments/5vo0fb/ Change-Id: I2ad6f03922b772f03e282a0af6eea24f8de9cef8 Reviewed-on: https://go-review.googlesource.com/37432 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
219e654bb7
commit
4968197297
@ -72,6 +72,14 @@ var _ foo.T
|
||||
"support move destinations whose base names are not valid " +
|
||||
"go identifiers",
|
||||
},
|
||||
{
|
||||
ctxt: fakeContext(map[string][]string{
|
||||
"foo": {``},
|
||||
"bar": {`package bar`},
|
||||
}),
|
||||
from: "foo", to: "bar",
|
||||
want: `no initial packages were loaded`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
@ -392,6 +392,9 @@ func loadProgram(ctxt *build.Context, pkgs map[string]bool) (*loader.Program, er
|
||||
// It would be nice if the loader API permitted "AllowErrors: soft".
|
||||
conf.AllowErrors = true
|
||||
prog, err := conf.Load()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var errpkgs []string
|
||||
// Report hard errors in indirectly imported packages.
|
||||
for _, info := range prog.AllPackages {
|
||||
@ -408,7 +411,7 @@ func loadProgram(ctxt *build.Context, pkgs map[string]bool) (*loader.Program, er
|
||||
return nil, fmt.Errorf("couldn't load packages due to errors: %s%s",
|
||||
strings.Join(errpkgs, ", "), more)
|
||||
}
|
||||
return prog, err
|
||||
return prog, nil
|
||||
}
|
||||
|
||||
func containsHardErrors(errors []error) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user