changeset 16022:d8f216d241cf

Fix off-by-1 error in run_history when called with no arguments. * libinterp/interpfcn/oct-hist.cc(mk_tmp_hist_file): Subtract 2 from hist_count to account for last command and zero-based indexing.
author Rik <rik@octave.org>
date Fri, 08 Feb 2013 17:37:14 -0800
parents 26cba49d7641
children 98fc95793699
files libinterp/interpfcn/oct-hist.cc
diffstat 1 files changed, 4 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/interpfcn/oct-hist.cc	Fri Feb 08 15:46:45 2013 -0800
+++ b/libinterp/interpfcn/oct-hist.cc	Fri Feb 08 17:37:14 2013 -0800
@@ -374,23 +374,21 @@
 
   string_vector hlist = command_history::list ();
 
-  int hist_count = hlist.length ();
+  int hist_count = hlist.length () - 1;  // switch to zero-based indexing
 
   // The current command line is already part of the history list by
   // the time we get to this point.  Delete it from the list.
 
-  hist_count -= 2;
-
   if (! insert_curr)
     command_history::remove (hist_count);
 
-  hist_count--;
+  hist_count--;  // skip last entry in history list
 
   // If no numbers have been specified, the default is to edit the
   // last command in the history list.
 
+  int hist_beg = hist_count;
   int hist_end = hist_count;
-  int hist_beg = hist_count;
 
   bool reverse = false;
 
@@ -436,9 +434,7 @@
 
   if (hist_end < hist_beg)
     {
-      int t = hist_end;
-      hist_end = hist_beg;
-      hist_beg = t;
+      std::swap (hist_end, hist_beg);
       reverse = true;
     }