Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/utils/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ func Uint64ToBytes(i uint64) []byte {
// to byteSlice will also modify the contents of the string, so it is the caller's responsibility
// to ensure that the byte slice will not modified after the string is created.
func UnsafeCastToString(byteSlice []byte) string {
return *(*string)(unsafe.Pointer(&byteSlice)) // #nosec G103
if len(byteSlice) == 0 {
return ""
}
return unsafe.String(unsafe.SliceData(byteSlice), len(byteSlice))
Comment thread
swarna1101 marked this conversation as resolved.
Outdated
}
6 changes: 5 additions & 1 deletion pkg/utils/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ func CalculateMaxSize(src int64) (int, error) {
if src <= 0 {
return 0, fmt.Errorf("src must be positive: %d", src)
}
maxAllowed := int64(math.MaxInt)
if src > maxAllowed-maxAllowed/5 {
return 0, fmt.Errorf("src is too large, final value not fit: %d", src)
}
finalVal := src + int64(float64(src)*0.2)
if finalVal < 0 || finalVal > math.MaxInt {
if finalVal < 0 || finalVal > maxAllowed {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
return 0, fmt.Errorf("src is too large, final value not fit: %d", src)
}
return int(finalVal), nil
Expand Down
Loading