mirror of
https://github.com/golang/go
synced 2024-11-05 14:56:10 -07:00
go/analysis/passes/unmarshal: Add check for asn1.Unmarshal
Unmarshal package checks whether `Unmarshal` and(or) `Decode` call of `encoding/json`, `encoding/xml` and `encoding/gob` package is valid or not. However, it didn't check `encoding/asn1` package's one. This change makes it check whether `asn1.Unmarshal` call is valid or not as well. Change-Id: If32d243f3a82ebb5ca3ca80657f4616e5daced2f GitHub-Last-Rev: e61a96941ee64d7d141e635b374fe07104751283 GitHub-Pull-Request: golang/tools#243 Reviewed-on: https://go-review.googlesource.com/c/tools/+/243397 Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
6123e77877
commit
7041913083
@ -7,6 +7,7 @@
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"encoding/asn1"
|
||||
"encoding/gob"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
@ -30,6 +31,8 @@ func _() {
|
||||
xml.Unmarshal([]byte{}, &v)
|
||||
xml.NewDecoder(r).Decode(v) // want "call of Decode passes non-pointer"
|
||||
xml.NewDecoder(r).Decode(&v)
|
||||
asn1.Unmarshal([]byte{}, v) // want "call of Unmarshal passes non-pointer as second argument"
|
||||
asn1.Unmarshal([]byte{}, &v)
|
||||
|
||||
var p *t
|
||||
json.Unmarshal([]byte{}, p)
|
||||
@ -42,6 +45,8 @@ func _() {
|
||||
xml.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
|
||||
xml.NewDecoder(r).Decode(p)
|
||||
xml.NewDecoder(r).Decode(*p) // want "call of Decode passes non-pointer"
|
||||
asn1.Unmarshal([]byte{}, p)
|
||||
asn1.Unmarshal([]byte{}, *p) // want "call of Unmarshal passes non-pointer as second argument"
|
||||
|
||||
var i interface{}
|
||||
json.Unmarshal([]byte{}, i)
|
||||
|
@ -30,7 +30,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
switch pass.Pkg.Path() {
|
||||
case "encoding/gob", "encoding/json", "encoding/xml":
|
||||
case "encoding/gob", "encoding/json", "encoding/xml", "encoding/asn1":
|
||||
// These packages know how to use their own APIs.
|
||||
// Sometimes they are testing what happens to incorrect programs.
|
||||
return nil, nil
|
||||
@ -54,8 +54,9 @@ func run(pass *analysis.Pass) (interface{}, error) {
|
||||
if fn.Name() == "Unmarshal" && recv == nil {
|
||||
// "encoding/json".Unmarshal
|
||||
// "encoding/xml".Unmarshal
|
||||
// "encoding/asn1".Unmarshal
|
||||
switch fn.Pkg().Path() {
|
||||
case "encoding/json", "encoding/xml":
|
||||
case "encoding/json", "encoding/xml", "encoding/asn1":
|
||||
argidx = 1 // func([]byte, interface{})
|
||||
}
|
||||
} else if fn.Name() == "Decode" && recv != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user