1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-02-10 21:43:16 +00:00

state: Fix out of bound panic in Messages (#235)

This commit is contained in:
Maximilian von Lindern 2021-06-25 07:46:27 +02:00 committed by GitHub
parent 6c349d9750
commit 8e4e48e25e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -700,7 +700,12 @@ func (s *State) Messages(channelID discord.ChannelID, limit uint) ([]discord.Mes
if s.tracksMessage(&apiMessages[0]) && len(storeMessages) < s.MaxMessages() {
// Only add as many messages as the store can hold.
for _, m := range apiMessages[:s.MaxMessages()-len(storeMessages)] {
i := s.MaxMessages() - len(storeMessages)
if i > len(apiMessages) {
i = len(apiMessages)
}
for _, m := range apiMessages[:i] {
if err := s.Cabinet.MessageSet(m, false); err != nil {
return nil, err
}