mirror of
https://github.com/golang/go
synced 2024-11-18 11:24:41 -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 " +
|
"support move destinations whose base names are not valid " +
|
||||||
"go identifiers",
|
"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 {
|
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".
|
// It would be nice if the loader API permitted "AllowErrors: soft".
|
||||||
conf.AllowErrors = true
|
conf.AllowErrors = true
|
||||||
prog, err := conf.Load()
|
prog, err := conf.Load()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
var errpkgs []string
|
var errpkgs []string
|
||||||
// Report hard errors in indirectly imported packages.
|
// Report hard errors in indirectly imported packages.
|
||||||
for _, info := range prog.AllPackages {
|
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",
|
return nil, fmt.Errorf("couldn't load packages due to errors: %s%s",
|
||||||
strings.Join(errpkgs, ", "), more)
|
strings.Join(errpkgs, ", "), more)
|
||||||
}
|
}
|
||||||
return prog, err
|
return prog, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func containsHardErrors(errors []error) bool {
|
func containsHardErrors(errors []error) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user