🔢 Fix index out of range

This commit is contained in:
database64128 2021-09-03 13:30:47 +08:00
parent 51b119107c
commit 3267ba827f
No known key found for this signature in database
GPG key ID: 1CA27546BEDB8B01

View file

@ -166,10 +166,16 @@ func (d *Database) AddState(
return 0, fmt.Errorf("d.StateBlockTable.BulkSelectStateBlockEntries: %w", berr)
}
for i := len(state) - 1; i >= 0; i-- {
for _, events := range blocks {
for j := 0; j < len(blocks) && i < len(state); j++ {
events := blocks[j]
for _, event := range events {
if state[i].EventNID == event {
if i+1 < len(state) {
state = append(state[:i], state[i+1:]...)
} else {
state = state[:i]
}
break
}
}
}