From 70646f9b069fdab69409d746ca255537fb2cd385 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Mon, 13 Feb 2023 15:38:01 -0800 Subject: [PATCH 1/3] workflowcheck: mark some fmt functions as deterministic --- contrib/tools/workflowcheck/determinism/ident_refs.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/tools/workflowcheck/determinism/ident_refs.go b/contrib/tools/workflowcheck/determinism/ident_refs.go index 2ee698250..fad4810da 100644 --- a/contrib/tools/workflowcheck/determinism/ident_refs.go +++ b/contrib/tools/workflowcheck/determinism/ident_refs.go @@ -38,6 +38,10 @@ var DefaultIdentRefs = IdentRefs{ // We mark these as deterministic since they give so many false positives "(reflect.Value).Interface": false, "runtime.Caller": false, + "fmt.Errorf": false, + "fmt.Sprintf": false, + "fmt.Sprint": false, + "fmt.Sprintln": false, // We are considering the global pseudorandom as non-deterministic by default // since it's global (even if they set a seed), but we allow use of a manually // instantiated random instance that may have a localized, fixed seed From 9c52284f22f0224dba67629557e3c257f3c1d6c5 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 14 Feb 2023 08:08:15 -0800 Subject: [PATCH 2/3] Add Append, and Sscan functions --- contrib/tools/workflowcheck/determinism/ident_refs.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/tools/workflowcheck/determinism/ident_refs.go b/contrib/tools/workflowcheck/determinism/ident_refs.go index fad4810da..7569dd273 100644 --- a/contrib/tools/workflowcheck/determinism/ident_refs.go +++ b/contrib/tools/workflowcheck/determinism/ident_refs.go @@ -38,10 +38,16 @@ var DefaultIdentRefs = IdentRefs{ // We mark these as deterministic since they give so many false positives "(reflect.Value).Interface": false, "runtime.Caller": false, + "fmt.Append": false, + "fmt.Appendf": false, + "fmt.Appendln": false, "fmt.Errorf": false, "fmt.Sprintf": false, "fmt.Sprint": false, "fmt.Sprintln": false, + "fmt.Sscan": false, + "fmt.Sscanf": false, + "fmt.Sscanln": false, // We are considering the global pseudorandom as non-deterministic by default // since it's global (even if they set a seed), but we allow use of a manually // instantiated random instance that may have a localized, fixed seed From be52eca9cac46a39b267deb91784eb9adcc90b84 Mon Sep 17 00:00:00 2001 From: Quinn Klassen Date: Tue, 14 Feb 2023 08:20:10 -0800 Subject: [PATCH 3/3] Add fmt.Sprintf unittest --- .../tools/workflowcheck/determinism/testdata/src/a/calls.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/tools/workflowcheck/determinism/testdata/src/a/calls.go b/contrib/tools/workflowcheck/determinism/testdata/src/a/calls.go index e80a379ec..55012052e 100644 --- a/contrib/tools/workflowcheck/determinism/testdata/src/a/calls.go +++ b/contrib/tools/workflowcheck/determinism/testdata/src/a/calls.go @@ -1,6 +1,7 @@ package a import ( + "fmt" "log" mathrand "math/rand" "net/http" @@ -57,3 +58,7 @@ func CallsMathRandom() { // want CallsMathRandom:"calls non-deterministic functi func CallsHTTP() { // want CallsHTTP:"calls non-deterministic function net/http.Get" http.Get("http://example.com") } + +func SafeFmtCall() { + fmt.Sprintf("foo bar") +}