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:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user