🩹 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
improve_docs
Kashiwa 2025-02-20 19:26:35 +08:00 committed by GitHub
parent b0bc32b534
commit 283ef32196
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 1 deletions

View File

@ -5522,6 +5522,10 @@ func Test_GenericParseTypeUints(t *testing.T) {
value: uint(4),
str: "4",
},
{
value: ^uint(0),
str: strconv.FormatUint(uint64(^uint(0)), 10),
},
}
for _, test := range uints {

View File

@ -796,7 +796,7 @@ func genericParseType[V GenericType](str string, v V, defaultValue ...V) V {
case int64:
return genericParseInt[V](str, 64, func(i int64) V { return assertValueType[V, int64](i) }, defaultValue...)
case uint:
return genericParseUint[V](str, 32, func(i uint64) V { return assertValueType[V, uint](uint(i)) }, defaultValue...)
return genericParseUint[V](str, 0, func(i uint64) V { return assertValueType[V, uint](uint(i)) }, defaultValue...)
case uint8:
return genericParseUint[V](str, 8, func(i uint64) V { return assertValueType[V, uint8](uint8(i)) }, defaultValue...)
case uint16: