From 92dda9cc3b0270361f5ace17e4060435ea43250f Mon Sep 17 00:00:00 2001 From: s7v7nislands Date: Tue, 25 Oct 2016 11:57:05 +0800 Subject: [PATCH 1/2] fix unsafe check --- rules/unsafe.go | 2 +- rules/unsafe_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/rules/unsafe.go b/rules/unsafe.go index 1d89ea9..d3d55c9 100644 --- a/rules/unsafe.go +++ b/rules/unsafe.go @@ -35,7 +35,7 @@ func (r *UsingUnsafe) Match(n ast.Node, c *gas.Context) (gi *gas.Issue, err erro func NewUsingUnsafe(conf map[string]interface{}) (r gas.Rule, n ast.Node) { r = &UsingUnsafe{ - pattern: regexp.MustCompile(`unsafe.*`), + pattern: regexp.MustCompile(`unsafe\..*`), MetaData: gas.MetaData{ What: "Use of unsafe calls should be audited", Severity: gas.Low, diff --git a/rules/unsafe_test.go b/rules/unsafe_test.go index 7714901..2b4f5c3 100644 --- a/rules/unsafe_test.go +++ b/rules/unsafe_test.go @@ -33,7 +33,13 @@ func TestUnsafe(t *testing.T) { "unsafe" ) + type Fake struct{} + + func (Fake) Good() {} + func main() { + unsafeM := Fake{} + unsafeM.Good() intArray := [...]int{1, 2} fmt.Printf("\nintArray: %v\n", intArray) intPtr := &intArray[0] From eedb0c279d382236369ec47d06260aebfb10a0b8 Mon Sep 17 00:00:00 2001 From: s7v7nislands Date: Tue, 25 Oct 2016 12:08:59 +0800 Subject: [PATCH 2/2] fix fmt --- rules/unsafe_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rules/unsafe_test.go b/rules/unsafe_test.go index 2b4f5c3..64f6d44 100644 --- a/rules/unsafe_test.go +++ b/rules/unsafe_test.go @@ -33,13 +33,13 @@ func TestUnsafe(t *testing.T) { "unsafe" ) - type Fake struct{} + type Fake struct{} - func (Fake) Good() {} + func (Fake) Good() {} func main() { - unsafeM := Fake{} - unsafeM.Good() + unsafeM := Fake{} + unsafeM.Good() intArray := [...]int{1, 2} fmt.Printf("\nintArray: %v\n", intArray) intPtr := &intArray[0]