mirror of
https://github.com/nabbar/golib.git
synced 2025-12-24 11:51:02 +08:00
Package Size:
- Fix constructor from int64 / float64 to prevent negative value - Fix false positive gosec in format
This commit is contained in:
@@ -61,7 +61,7 @@ func (s Size) Int64() int64 {
|
||||
return math.MaxInt64
|
||||
}
|
||||
|
||||
return int64(s)
|
||||
return int64(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Int32() int32 {
|
||||
@@ -70,7 +70,7 @@ func (s Size) Int32() int32 {
|
||||
return math.MaxInt32
|
||||
}
|
||||
|
||||
return int32(s)
|
||||
return int32(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Int() int {
|
||||
@@ -79,7 +79,7 @@ func (s Size) Int() int {
|
||||
return math.MaxInt
|
||||
}
|
||||
|
||||
return int(s)
|
||||
return int(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Uint64() uint64 {
|
||||
@@ -92,7 +92,7 @@ func (s Size) Uint32() uint32 {
|
||||
return math.MaxUint32
|
||||
}
|
||||
|
||||
return uint32(s)
|
||||
return uint32(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Uint() uint {
|
||||
@@ -101,7 +101,7 @@ func (s Size) Uint() uint {
|
||||
return math.MaxUint
|
||||
}
|
||||
|
||||
return uint(s)
|
||||
return uint(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Float64() float64 {
|
||||
@@ -110,7 +110,7 @@ func (s Size) Float64() float64 {
|
||||
return math.MaxFloat64
|
||||
}
|
||||
|
||||
return float64(s)
|
||||
return float64(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Float32() float32 {
|
||||
@@ -119,7 +119,7 @@ func (s Size) Float32() float32 {
|
||||
return math.MaxFloat32
|
||||
}
|
||||
|
||||
return float32(s)
|
||||
return float32(s) // #nosec
|
||||
}
|
||||
|
||||
func (s Size) Format(format string) string {
|
||||
|
||||
@@ -63,8 +63,11 @@ func GetSize(s string) (sizeBytes Size, success bool) {
|
||||
}
|
||||
|
||||
func SizeFromInt64(val int64) Size {
|
||||
v := uint64(val)
|
||||
return Size(v)
|
||||
if val < 0 {
|
||||
return Size(uint64(-val))
|
||||
} else {
|
||||
return Size(uint64(val))
|
||||
}
|
||||
}
|
||||
|
||||
func SizeFromFloat64(val float64) Size {
|
||||
@@ -74,8 +77,10 @@ func SizeFromFloat64(val float64) Size {
|
||||
return Size(uint64(math.MaxUint64))
|
||||
} else if -val > math.MaxUint64 {
|
||||
return Size(uint64(math.MaxUint64))
|
||||
} else {
|
||||
} else if val > 0 {
|
||||
return Size(uint64(val))
|
||||
} else {
|
||||
return Size(uint64(-val))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user