From f6683fefea96408d2915e501f774ab4a5250a661 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 11 Oct 2020 14:05:37 -0400 Subject: [PATCH] avoid segfault on the last word of the command history --- tools/lammps-shell/lammps-shell.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/lammps-shell/lammps-shell.cpp b/tools/lammps-shell/lammps-shell.cpp index 21b8ef8c7a..08a4176770 100644 --- a/tools/lammps-shell/lammps-shell.cpp +++ b/tools/lammps-shell/lammps-shell.cpp @@ -229,7 +229,8 @@ static char *cmd_generator(const char *text, int state) len = strlen(text); do { - if ((len == 0) || (commands[idx].substr(0, len) == text)) + if ((idx < commands.size()) + && ((len == 0) || (commands[idx].substr(0, len) == text))) return dupstring(commands[idx++]); else ++idx;