From 897e8085ba81d85e00226713e65ae71e60f9f3e2 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Fri, 25 Jul 2008 08:55:26 +0000 Subject: 25338: disallow usage of current history line in fc --- Src/builtin.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index c7ed283a9..9465bb5a0 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -1446,6 +1446,20 @@ bin_fc(char *nam, char **argv, Options ops, int func) unqueue_signals(); zwarnnam("fc", "can't open temp file: %e", errno); } else { + /* + * Nasty behaviour results if we use the current history + * line here. Treat it as if it doesn't exist, unless + * that gives us an empty range. + */ + if (last >= curhist) { + last = curhist - 1; + if (first > last) { + unqueue_signals(); + zwarnnam("fc", "invalid use of current history line"); + unlink(fil); + return 1; + } + } ops->ind['n'] = 1; /* No line numbers here. */ if (!fclist(out, ops, first, last, asgf, pprog)) { char *editor; -- cgit 1.4.1