Skip to content

Commit 314b2fa

Browse files
committed
go sec fix
1 parent fa73682 commit 314b2fa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

spectrocloud/common/safe_conversions.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ func SafeUint32(value int) uint32 {
99
// On 64-bit systems, we need to check against uint32 max
1010
if ^uint(0)>>32 == 0 {
1111
// 32-bit system: int and uint32 have same size, no overflow possible
12-
return uint32(value)
12+
if value >= 0 {
13+
return uint32(value)
14+
}
15+
return 0
1316
}
1417
// 64-bit system: check against uint32 max
1518
if uint64(value) > 0xFFFFFFFF {
1619
return 0xFFFFFFFF
1720
}
18-
return uint32(value)
21+
if value >= 0 {
22+
return uint32(value)
23+
}
24+
return 0
1925
}

0 commit comments

Comments
 (0)