aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorChris Luke <chrisy@flirble.org>2019-05-17 10:17:16 -0400
committerChris Luke <chrisy@flirble.org>2019-05-17 10:28:34 -0400
commit5022c6ce34b5215e63a4ea5972ca0ed0fd196ab0 (patch)
treef66add0066ed37b1e1ac6e81e26dfd130845e2bd /src/vlib
parentd8a34a57b12200000bb42d1c55f1a99a0a473f4b (diff)
Fix 'terminal history off' crasher
- 'set terminal history off' or '... limit 0' has an incorrect terminal condition and tries to vec_delete one-too-many times causing a crash. - Changing >= to > fixes this. - In any case, a single vec_delete is more efficient, so do that instead. Change-Id: Ia0db63b6c5c7891d75b302e793b4e4985dd86ebb Signed-off-by: Chris Luke <chrisy@flirble.org>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/unix/cli.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/vlib/unix/cli.c b/src/vlib/unix/cli.c
index f9d6b40c4d5..2d5a22dc66a 100644
--- a/src/vlib/unix/cli.c
+++ b/src/vlib/unix/cli.c
@@ -3603,14 +3603,21 @@ unix_cli_set_terminal_history (vlib_main_t * vm,
goto done;
}
- /* If we reduced history size, or turned it off, purge the history */
- limit = cf->has_history ? cf->history_limit : 0;
+ }
- while (cf->command_history && vec_len (cf->command_history) >= limit)
- {
- vec_free (cf->command_history[0]);
- vec_delete (cf->command_history, 1, 0);
- }
+ /* If we reduced history size, or turned it off, purge the history */
+ limit = cf->has_history ? cf->history_limit : 0;
+ if (limit < vec_len (cf->command_history))
+ {
+ u32 i;
+
+ /* How many items to remove from the start of history */
+ limit = vec_len (cf->command_history) - limit;
+
+ for (i = 0; i < limit; i++)
+ vec_free (cf->command_history[i]);
+
+ vec_delete (cf->command_history, limit, 0);
}
done: