Skip to content

Commit

Permalink
fix(toc): fixed out of range array access
Browse files Browse the repository at this point in the history
  • Loading branch information
hadjian committed Nov 28, 2023
1 parent 50f7f65 commit 7c7ce7f
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions internal/model/toc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

import (
"slices"
"strings"
"time"

Expand Down Expand Up @@ -37,13 +38,9 @@ type TOCVersion struct {
}

func (toc *TOC) Filter(filter string) {
for index, value := range toc.Data {
if !matchFilter(*value, filter) {
// zero the reference to make it garbage collected
toc.Data[index] = &TOCEntry{}
toc.Data = append(toc.Data[:index], toc.Data[index+1:]...)
}
}
toc.Data = slices.DeleteFunc(toc.Data, func(tocEntry *TOCEntry) bool {
return !matchFilter(*tocEntry, filter)
})
}

func matchFilter(entry TOCEntry, filter string) bool {
Expand Down

0 comments on commit 7c7ce7f

Please sign in to comment.