Skip to content

Commit

Permalink
hungarian: fix panic in stem1, stem5 (length check)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgulacsi committed Nov 12, 2023
1 parent 51e8821 commit e523260
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hungarian/stem.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ func step1(w *snowballword.SnowballWord) {
return
}
// in R1
if w.R1start > n-2 {
if w.R1start > n-2 || n < 4 {
return
}
// (In the case of consonant plus digraph, such as ccs, remove a c).
if isDoubleConsonant(w.RS[n-5:n-2]) > 2 {
if n >= 5 && isDoubleConsonant(w.RS[n-5:n-2]) > 2 {
w.RS[n-5], w.RS[n-4] = w.RS[n-4], w.RS[n-3]
w.RemoveLastNRunes(3)
} else if isDoubleConsonant(w.RS[n-4:n-2]) > 1 {
} else if n >= 4 && isDoubleConsonant(w.RS[n-4:n-2]) > 1 {
// preceded by a double consonant
w.RemoveLastNRunes(3)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func step5(w *snowballword.SnowballWord) {
return
}
// (In the case of consonant plus digraph, such as ccs, remove a c).
if isDoubleConsonant(w.RS[n-4:n-1]) > 2 {
if n >= 4 && isDoubleConsonant(w.RS[n-4:n-1]) > 2 {
w.RS[n-4], w.RS[n-3] = w.RS[n-3], w.RS[n-1]
w.RemoveLastNRunes(2)
} else if isDoubleConsonant(w.RS[n-3:n-1]) > 1 {
Expand Down

0 comments on commit e523260

Please sign in to comment.