From 8467f012e0d6238433e299fd0499ee29342000c3 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Wed, 21 Aug 2024 12:36:33 +0000 Subject: [PATCH] Add more test to cover more use cases for G115 rule Change-Id: Icb60fe14ae12439c1ee0e507a407a23ce4c64c85 Signed-off-by: Cosmin Cojocar --- testutils/g115_samples.go | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/testutils/g115_samples.go b/testutils/g115_samples.go index 0f33b26..29f992f 100644 --- a/testutils/g115_samples.go +++ b/testutils/g115_samples.go @@ -176,6 +176,36 @@ func main() { ` package main +import ( + "fmt" +) + +func main() { + var a byte = '\xff' + b := int64(a) + fmt.Println(b) +} + `, + }, 0, gosec.NewConfig()}, + {[]string{ + ` +package main + +import ( + "fmt" +) + +func main() { + var a int8 = -1 + b := int64(a) + fmt.Println(b) +} + `, + }, 0, gosec.NewConfig()}, + {[]string{ + ` +package main + import ( "fmt" "math" @@ -187,6 +217,21 @@ func main() { var a uint = math.MaxUint b := CustomType(a) fmt.Println(b) +} + `, + }, 1, gosec.NewConfig()}, + {[]string{ + ` +package main + +import ( + "fmt" +) + +func main() { + a := []int{1,2,3} + b := uint32(len(a)) + fmt.Println(b) } `, }, 1, gosec.NewConfig()},