1
0
mirror of https://github.com/golang/go synced 2024-09-30 12:18:33 -06: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:
David R. Jenni 2017-02-23 18:31:04 +01:00 committed by Alan Donovan
parent 219e654bb7
commit 4968197297
2 changed files with 12 additions and 1 deletions

View File

@ -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 {

View File

@ -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 {