walles / moar

Moar is a pager. It's designed to just do the right thing without any configuration.
Other
587 stars 17 forks source link

crash when searching #167

Closed andyrtr closed 7 months ago

andyrtr commented 7 months ago

moar version 1.18.4 crashes here when seaching by "/" and typing "lt_extla" (string to search is "lt_extlang_t") when hitting letter "a":

moar /usr/share/gir-1.0/LangTag-0.6.gir
Please post the following report at <https://github.com/walles/moar/issues>,
or e-mail it to johan.walles@gmail.com.

Version: 1.18.4
LANG   : de_DE.UTF-8
TERM   : foot

GOOS    : linux
GOARCH  : amd64
Compiler: gc
NumCPU  : 16

panic: lineNumberString <1000 > longer than numberPrefixLength 4 [recovered]
    panic: lineNumberString <1000 > longer than numberPrefixLength 4 [recovered]
    panic: lineNumberString <1000 > longer than numberPrefixLength 4

goroutine 1 [running]:
main.main.func1()
    github.com/walles/moar/moar.go:333 +0x155
panic({0x55fb9a8468e0?, 0xc000550dc0?})
    runtime/panic.go:914 +0x21f
main.startPaging.func1()
    github.com/walles/moar/moar.go:538 +0xb0
panic({0x55fb9a8468e0?, 0xc000550dc0?})
    runtime/panic.go:914 +0x21f
github.com/walles/moar/m.createLinePrefix(0xc000325708, 0x4)
    github.com/walles/moar/m/screenLines.go:315 +0x315
github.com/walles/moar/m.(*Pager).decorateLine(0xc000598000, 0xc00001a210?, {0xc000306800, 0x39, 0x39})
    github.com/walles/moar/m/screenLines.go:258 +0x90
github.com/walles/moar/m.(*Pager).renderLine(0xc000598000, 0xc000088050?, 0x3e8)
    github.com/walles/moar/m/screenLines.go:229 +0x295
github.com/walles/moar/m.(*scrollPositionInternal).emptyBottomLinesCount(0xc000088050, 0xc000598000)
    github.com/walles/moar/m/scrollPosition.go:168 +0x8e
github.com/walles/moar/m.(*scrollPositionInternal).canonicalize(0xc000088050, 0xc000598000)
    github.com/walles/moar/m/scrollPosition.go:249 +0x189
github.com/walles/moar/m.(*scrollPosition).lineNumberOneBased(...)
    github.com/walles/moar/m/scrollPosition.go:276
github.com/walles/moar/m.scrollPosition.isVisible({{0x36b, 0x0, {0x55fb9a55dfff, 0xc}, 0x0, {0x0, 0x0, 0x0, 0x0, 0x0, ...}}}, ...)
    github.com/walles/moar/m/scrollPosition.go:206 +0x65
github.com/walles/moar/m.(*Pager).scrollToSearchHits(0xc000598000)
    github.com/walles/moar/m/search.go:45 +0xe5
github.com/walles/moar/m.(*Pager).updateSearchPattern(0xc000598000)
    github.com/walles/moar/m/search.go:164 +0x65
github.com/walles/moar/m.(*Pager).onSearchRune(...)
    github.com/walles/moar/m/search.go:260
github.com/walles/moar/m.(*Pager).onRune(0xc000598000, 0x0?)
    github.com/walles/moar/m/pager.go:334 +0xe25
github.com/walles/moar/m.(*Pager).StartPaging(0xc000598000, {0x55fb9a876d20?, 0xc0000c50e0})
    github.com/walles/moar/m/pager.go:569 +0x525
main.startPaging(0xc00014c070?, {0x55fb9a876d20?, 0xc0000c50e0?})
    github.com/walles/moar/moar.go:549 +0x6f
main.main()
    github.com/walles/moar/moar.go:509 +0x10d2

The file has 5097 lines. Do you need any further info?

walles commented 7 months ago

Dup of #166.

Nope, I think I'm good.

At least in theory I think it should be easy to just write a unit test for createLinePrefix() based on that lineNumberString <1000 > longer than numberPrefixLength 4 message and make it stop crashing.

Thanks for the report @andyrtr!