Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: runtime error: slice bounds out of range #110

Open
shreyassreenivas opened this issue Oct 26, 2018 · 5 comments · May be fixed by #241
Open

panic: runtime error: slice bounds out of range #110

shreyassreenivas opened this issue Oct 26, 2018 · 5 comments · May be fixed by #241

Comments

@shreyassreenivas
Copy link

b.setText(string(or[:oc]) + v + string(or[oc+len(overwritten):]))

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())
}

@c-bata
Copy link
Owner

c-bata commented Oct 26, 2018

@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

@shreyassreenivas shreyassreenivas changed the title panic: runtime error: slice bounds out of rang panic: runtime error: slice bounds out of range Oct 27, 2018
@shreyassreenivas
Copy link
Author

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 63e3a6f

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

@c-bata
Copy link
Owner

c-bata commented Oct 27, 2018

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

@rohityadavcloud
Copy link

@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

@sumedho
Copy link

sumedho commented Feb 9, 2019

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants