Skip to content

Commit

Permalink
Fix crash when looking for matching bracket before any brackets
Browse files Browse the repository at this point in the history
i >= 0 was always true, because the index was unsigned.
  • Loading branch information
driusan committed May 3, 2020
1 parent 8f5cf00 commit 0efad91
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions position/positions.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ func MatchingBracket(buff demodel.CharBuffer) (uint, error) {
extraround := 0
extrasquare := 0
extraangle := 0
for i := buff.Dot.Start - 1; i >= 0; i-- {
for i := int(buff.Dot.Start - 1); i >= 0; i-- {
// If there was a block inside this block, skip it
if buff.Buffer[i] == '}' {
extrasquigly++
Expand All @@ -505,25 +505,25 @@ func MatchingBracket(buff demodel.CharBuffer) (uint, error) {
if extrasquigly > 0 {
extrasquigly--
} else {
return i, nil
return uint(i), nil
}
} else if buff.Buffer[i] == '(' {
if extraround > 0 {
extraround--
} else {
return i, nil
return uint(i), nil
}
} else if buff.Buffer[i] == '[' {
if extrasquare > 0 {
extrasquare--
} else {
return i, nil
return uint(i), nil
}
} else if buff.Buffer[i] == '<' {
if extraangle > 0 {
extraangle--
} else {
return i, nil
return uint(i), nil
}
}
}
Expand Down

0 comments on commit 0efad91

Please sign in to comment.