go-prompt icon indicating copy to clipboard operation
go-prompt copied to clipboard

panic: runtime error: slice bounds out of range

Open shreyassreenivas opened this issue 7 years ago • 5 comments

https://github.com/c-bata/go-prompt/blob/63e3a6f38aca443ea14c57bf6cde497a6ebd4062/buffer.go#L52

panic: runtime error: slice bounds out of range [recovered] panic: runtime error: slice bounds out of range

goroutine 6 [running]: testing.tRunner.func1(0xc0000aa300) /usr/local/go/src/testing/testing.go:792 +0x387 panic(0x111bb00, 0x122e800) /usr/local/go/src/runtime/panic.go:513 +0x1b9 github.com/c-bata/go-prompt.(*Buffer).InsertText(0xc000040760, 0x11417e9, 0x3, 0x1050101) vendor/github.com/c-bata/go-prompt/buffer.go:52 +0x43d

sample code used :

func TestCLIPrompt_Completer(t *testing.T) { buffer := goPrompt.NewBuffer() buffer.InsertText("one", true, true) // this results in the panic fmt.Println(buffer.Document()) buffer.CursorRight(2) fmt.Println(buffer.Document()) }

shreyassreenivas avatar Oct 26 '18 12:10 shreyassreenivas

@shreyas165 Thanks for reporting.

Could you update issue description to follow the format of issue template? At least, I need to know the context information about your operating system, terminal emulator and the revision of go-prompt. https://github.com/c-bata/go-prompt/blob/master/.github/ISSUE_TEMPLATE.md

c-bata avatar Oct 26 '18 14:10 c-bata

Operating System: Mac OS 10.13 Terminal Emulator: (i.e. iTerm2) : This issue was not reproduced using terminal, It was a TestCase evaluation. tag of go-prompt or commit revision: pulled the lastest master 63e3a6f38aca443ea14c57bf6cde497a6ebd4062

The sample test case which was used when the issue occurred : func TestCLIPrompt_Completer(t *testing.T) { buffer := goPrompt.NewBuffer() buffer.InsertText("one", true, true) // this results in the panic fmt.Println(buffer.Document()) buffer.CursorRight(2) fmt.Println(buffer.Document()) }

run the above test in a golang editor or probably gotest will result in the above mentioned panic

shreyassreenivas avatar Oct 27 '18 13:10 shreyassreenivas

Thanks. Could you rewrite the issue description in following format? https://github.com/c-bata/go-prompt/blob/master/.github/ISSUE_TEMPLATE.md

c-bata avatar Oct 27 '18 16:10 c-bata

@c-bata I fixed a similar issue using:

**--- a/vendor/github.com/c-bata/go-prompt/completion.go
+++ b/vendor/github.com/c-bata/go-prompt/completion.go
@@ -41,7 +41,7 @@ type CompletionManager struct {
 
 // GetSelectedSuggestion returns the selected item.
 func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool) {
-       if c.selected == -1 {
+       if c.selected == -1 || len(c.tmp) < 1 {
                return Suggest{}, false

rohityadavcloud avatar Dec 01 '18 18:12 rohityadavcloud

I am getting the same error when trying to bind a Shortcut key to insert text into the prompt buffer. OS: Mojave 10.14.1 Terminal: OSX Terminal Version 2.9.1

// this works but clears the terminal
buf.InsertText("test string", false, true)

// this fails with "panic: runtime error: slice bounds out of range"
buf.InsertText("test string", true, true)

sumedho avatar Feb 09 '19 13:02 sumedho