Skip to content

Commit 743a394

Browse files
(gosec) Apply G115 fixes to internal/decimal128 package
Address gosec G115 integer overflow warnings in decimal128: - Use nolint for bitmask operations (14-bit values always fit in int) - Use nolint for modulo result conversions (always fit in uint32) - Document why conversions are safe
1 parent 4891120 commit 743a394

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

internal/decimal128/decimal128.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func divmod(h, l uint64, div uint32) (qh, ql uint64, rem uint32) {
3030
d := cr<<32 + l&(1<<32-1)
3131
dq := d / div64
3232
dr := d % div64
33+
//nolint:gosec // G115: dr is result of modulo, always fits in uint32
3334
return (aq<<32 | bq), (cq<<32 | dq), uint32(dr)
3435
}
3536

@@ -54,11 +55,13 @@ func String(h, l uint64) string {
5455
if h>>61&3 == 3 {
5556
// Bits: 1*sign 2*ignored 14*exponent 111*significand.
5657
// Implicit 0b100 prefix in significand.
58+
//nolint:gosec // G115: 14-bit value always fits in int
5759
exp = int(h >> 47 & (1<<14 - 1))
5860
// Spec says all of these values are out of range.
5961
high, low = 0, 0
6062
} else {
6163
// Bits: 1*sign 14*exponent 113*significand
64+
//nolint:gosec // G115: 14-bit value always fits in int
6265
exp = int(h >> 49 & (1<<14 - 1))
6366
high = h & (1<<49 - 1)
6467
}

0 commit comments

Comments
 (0)