vulncheck: add FuncNode.String
It is a little tricky to get right and is useful outside
of the package.
Cherry-picked: https://go-review.googlesource.com/c/exp/+/380435
Change-Id: Id6977829cad3598c0a4df0378bb3a9c2ca7c7b7c
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/395055
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/vulncheck/helpers_test.go b/vulncheck/helpers_test.go
index b275d78..ddfe8ec 100644
--- a/vulncheck/helpers_test.go
+++ b/vulncheck/helpers_test.go
@@ -106,23 +106,16 @@
// seen edges, to avoid repetitions
seen := make(map[edge]bool)
- funcName := func(fn *FuncNode) string {
- if fn.RecvType == "" {
- return fmt.Sprintf("%s.%s", fn.PkgPath, fn.Name)
- }
- return fmt.Sprintf("%s.%s", fn.RecvType, fn.Name)
- }
-
m := make(map[string][]string)
for _, n := range cg.Functions {
- fName := funcName(n)
+ fName := n.String()
for _, callsite := range n.CallSites {
e := edge{src: callsite.Parent, dst: n.ID}
if seen[e] {
continue
}
caller := cg.Functions[e.src]
- callerName := funcName(caller)
+ callerName := caller.String()
m[callerName] = append(m[callerName], fName)
}
}
diff --git a/vulncheck/vulncheck.go b/vulncheck/vulncheck.go
index 0adf96f..8025ca4 100644
--- a/vulncheck/vulncheck.go
+++ b/vulncheck/vulncheck.go
@@ -179,6 +179,13 @@
CallSites []*CallSite
}
+func (fn *FuncNode) String() string {
+ if fn.RecvType == "" {
+ return fmt.Sprintf("%s.%s", fn.PkgPath, fn.Name)
+ }
+ return fmt.Sprintf("%s.%s", fn.RecvType, fn.Name)
+}
+
type CallSite struct {
// Parent is ID of the enclosing function where the call is made.
Parent int