Skip to content

Commit 283ef32

Browse files
authored
🩹 Fix: genericParseType parsing large uint leads to overflow (#3315)
* 🩹 Fix: genericParseType parsing large uint leads to overflow * ♻️ Refactor: use strconv.FormatUint instead of fmt.Sprintf
1 parent b0bc32b commit 283ef32

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ctx_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5522,6 +5522,10 @@ func Test_GenericParseTypeUints(t *testing.T) {
55225522
value: uint(4),
55235523
str: "4",
55245524
},
5525+
{
5526+
value: ^uint(0),
5527+
str: strconv.FormatUint(uint64(^uint(0)), 10),
5528+
},
55255529
}
55265530

55275531
for _, test := range uints {

helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ func genericParseType[V GenericType](str string, v V, defaultValue ...V) V {
796796
case int64:
797797
return genericParseInt[V](str, 64, func(i int64) V { return assertValueType[V, int64](i) }, defaultValue...)
798798
case uint:
799-
return genericParseUint[V](str, 32, func(i uint64) V { return assertValueType[V, uint](uint(i)) }, defaultValue...)
799+
return genericParseUint[V](str, 0, func(i uint64) V { return assertValueType[V, uint](uint(i)) }, defaultValue...)
800800
case uint8:
801801
return genericParseUint[V](str, 8, func(i uint64) V { return assertValueType[V, uint8](uint8(i)) }, defaultValue...)
802802
case uint16:

0 commit comments

Comments
 (0)