1
0
mirror of https://github.com/fumiama/go-base16384.git synced 2026-06-05 00:32:52 +08:00

fix: encode panic

This commit is contained in:
源文雨
2022-07-07 00:08:32 +08:00
committed by GitHub
parent 9db76d108c
commit ebe73ccc6c

View File

@@ -9,6 +9,20 @@ import "encoding/binary"
func encode(offset, outlen int, b, encd []byte) {
var n int
i := 0
if len(b) == 7 {
b = append(b, 0)
shift := binary.BigEndian.Uint64(b[i:]) >> 2
sum := shift
sum &= 0x3fff000000000000
shift >>= 2
sum |= shift & 0x00003fff00000000
shift >>= 2
sum |= shift & 0x000000003fff0000
shift >>= 2
sum |= shift & 0x0000000000003fff
sum += 0x4e004e004e004e00
binary.BigEndian.PutUint64(encd[n:], sum)
} else {
for ; i <= len(b)-7; i += 7 {
shift := binary.BigEndian.Uint64(b[i:]) >> 2
sum := shift
@@ -53,6 +67,7 @@ func encode(offset, outlen int, b, encd []byte) {
encd[outlen-2] = '='
encd[outlen-1] = byte(offset)
}
}
}
//go:nosplit