From c914be64f07d9998f52bf0d598ec26d457168c0f Mon Sep 17 00:00:00 2001 From: Remi Reuvekamp Date: Sun, 6 Nov 2016 05:23:43 +0100 Subject: [PATCH] Fix panic: runtime error: slice bounds out of range (#94) Reslicing line[10:] went wrong if only 'setprompt' was entered, without a space after. --- example/readline-demo/readline-demo.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/example/readline-demo/readline-demo.go b/example/readline-demo/readline-demo.go index e6c0a53..cb6fb1a 100644 --- a/example/readline-demo/readline-demo.go +++ b/example/readline-demo/readline-demo.go @@ -127,12 +127,11 @@ func main() { println("you set:", strconv.Quote(string(pswd))) } case strings.HasPrefix(line, "setprompt"): - prompt := line[10:] - if prompt == "" { + if len(line) <= 10 { log.Println("setprompt ") break } - l.SetPrompt(prompt) + l.SetPrompt(line[10:]) case strings.HasPrefix(line, "say"): line := strings.TrimSpace(line[3:]) if len(line) == 0 {