junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
64.3k stars 2.38k forks source link

Divide by zero with --tiebreak=end for long-line inputs #3846

Closed sergei-grechanik closed 3 months ago

sergei-grechanik commented 3 months ago

Checklist

Output of fzf --version

0.53.0 (c4a9ccd)

OS

Shell

Problem / Steps to reproduce

Running

seq -s ' ' 100000 | fzf   --tiebreak=end --query 1

will produce this error:

panic: runtime error: integer divide by zero

goroutine 27 [running]:
github.com/junegunn/fzf/src.buildResult(0xc00027b000, {0xc00001a198?, 0x5?, 0xc0000554e8?}, 0x24)
github.com/junegunn/fzf/src/result.go:84 +0x47e
github.com/junegunn/fzf/src.(*Pattern).MatchItem(0xc0000c2000, 0xc000055608?, 0x10?, 0x10000000001?)
github.com/junegunn/fzf/src/pattern.go:312 +0xa5
github.com/junegunn/fzf/src.(*Pattern).matchChunk(0xc0000c2000, 0xc00027b000, {0x0?, 0x7dd249067108?, 0x7dd24905e5b8?}, 0x18?)
github.com/junegunn/fzf/src/pattern.go:294 +0xf6
github.com/junegunn/fzf/src.(*Pattern).Match(0xc0000c2000, 0xc0000b8450?, 0xc0000834c8?)
github.com/junegunn/fzf/src/pattern.go:281 +0xa6
github.com/junegunn/fzf/src.(*Matcher).scan.func1(0x0, 0x0?, {0xc0000b6028, 0x1, 0x0?})
github.com/junegunn/fzf/src/matcher.go:184 +0x178
created by github.com/junegunn/fzf/src.(*Matcher).scan
github.com/junegunn/fzf/src/matcher.go:179 +0x578
junegunn commented 3 months ago

Thanks for the report. Fixed on master.