1
0
mirror of https://github.com/garraflavatra/go-fmp.git synced 2025-06-28 04:25:11 +00:00

Store everything in uint64 to avoid overflow

This commit is contained in:
2025-06-12 11:52:09 +02:00
parent 8562e1147b
commit d715fe6e64
5 changed files with 55 additions and 60 deletions

View File

@ -1,14 +1,14 @@
package fmp
func parseVarUint32(payload []byte) uint32 {
var length uint32
func parseVarUint64(payload []byte) uint64 {
var length uint64
n := len(payload)
if n > 4 {
n = 4 // clamp to max uint32
if n > 8 {
n = 8 // clamp to max uint64
}
for i := range n {
length <<= 8
length |= uint32(payload[i])
length |= uint64(payload[i])
}
return length
}