diff --git a/triedb/pathdb/history_trienode.go b/triedb/pathdb/history_trienode.go index 05a43808c2..11d6112806 100644 --- a/triedb/pathdb/history_trienode.go +++ b/triedb/pathdb/history_trienode.go @@ -391,10 +391,6 @@ func decodeKeyEntry(keySection []byte, offset int) (uint64, uint64, []byte, int, // decodeRestartTrailer resolves all the offsets recorded at the trailer. func decodeRestartTrailer(keySection []byte) ([]uint32, []uint32, int, error) { - var ( - keyOffsets []uint32 - valOffsets []uint32 - ) // Decode the number of restart section if len(keySection) < 4 { return nil, nil, 0, fmt.Errorf("key section too short, size: %d", len(keySection)) @@ -402,6 +398,10 @@ func decodeRestartTrailer(keySection []byte) ([]uint32, []uint32, int, error) { nRestarts := binary.BigEndian.Uint32(keySection[len(keySection)-4:]) // Decode the trailer + var ( + keyOffsets = make([]uint32, 0, int(nRestarts)) + valOffsets = make([]uint32, 0, int(nRestarts)) + ) if len(keySection) < int(8*nRestarts)+4 { return nil, nil, 0, fmt.Errorf("key section too short, restarts: %d, size: %d", nRestarts, len(keySection)) }