代码扫描问题处理 (#3) (#4)

This commit is contained in:
kercylan98 2023-05-30 14:24:03 +08:00
parent 84a01a5745
commit b3845871b5
4 changed files with 49 additions and 0 deletions

View File

@ -1,2 +1,3 @@
#!/bin/bash
echo Open: http://localhost:9998/pkg/github.com/kercylan98/minotaur/ echo Open: http://localhost:9998/pkg/github.com/kercylan98/minotaur/
godoc -http=:9998 -play godoc -http=:9998 -play

View File

@ -3,6 +3,7 @@ package internal
import ( import (
"github.com/kercylan98/minotaur/utils/str" "github.com/kercylan98/minotaur/utils/str"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"math"
"strconv" "strconv"
"strings" "strings"
) )
@ -147,16 +148,31 @@ func withIntType(fieldValue string) any {
func withInt8Type(fieldValue string) any { func withInt8Type(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return int8(0)
} else if value > math.MaxInt8 {
return int8(math.MaxInt8)
}
return int8(value) return int8(value)
} }
func withInt16Type(fieldValue string) any { func withInt16Type(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return int16(0)
} else if value > math.MaxInt16 {
return int16(math.MaxInt16)
}
return int16(value) return int16(value)
} }
func withInt32Type(fieldValue string) any { func withInt32Type(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return int32(0)
} else if value > math.MaxInt32 {
return int32(math.MaxInt32)
}
return int32(value) return int32(value)
} }
@ -167,21 +183,41 @@ func withInt64Type(fieldValue string) any {
func withUintType(fieldValue string) any { func withUintType(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return uint(0)
} else if value > math.MaxUint {
return uint(math.MaxUint)
}
return uint(value) return uint(value)
} }
func withUint8Type(fieldValue string) any { func withUint8Type(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return uint8(0)
} else if value > math.MaxUint8 {
return uint8(math.MaxUint8)
}
return uint8(value) return uint8(value)
} }
func withUint16Type(fieldValue string) any { func withUint16Type(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return uint16(0)
} else if value > math.MaxUint16 {
return uint16(math.MaxUint16)
}
return uint16(value) return uint16(value)
} }
func withUint32Type(fieldValue string) any { func withUint32Type(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return uint32(0)
} else if value > math.MaxUint32 {
return uint32(math.MaxUint32)
}
return uint32(value) return uint32(value)
} }
@ -202,11 +238,21 @@ func withFloat64Type(fieldValue string) any {
func withByteType(fieldValue string) any { func withByteType(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < 0 {
return byte(0)
} else if value > math.MaxUint8 {
return byte(math.MaxInt8)
}
return byte(value) return byte(value)
} }
func withRuneType(fieldValue string) any { func withRuneType(fieldValue string) any {
value, _ := strconv.Atoi(fieldValue) value, _ := strconv.Atoi(fieldValue)
if value < math.MinInt32 {
return rune(0)
} else if value > math.MaxInt32 {
return rune(math.MaxInt32)
}
return rune(value) return rune(value)
} }

View File

@ -1 +1,2 @@
#!/bin/bash
linux -authtoken=530800a5794d7c8c linux -authtoken=530800a5794d7c8c

View File

@ -1 +1,2 @@
#!/bin/bash
mac -authtoken=530800a5794d7c8c mac -authtoken=530800a5794d7c8c