# HG changeset patch # User Rik # Date 1360373834 28800 # Node ID d8f216d241cf5e319eb842ba4e2489215daa68d5 # Parent 26cba49d764169c40551d49ba242343cbba975d5 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. diff -r 26cba49d7641 -r d8f216d241cf libinterp/interpfcn/oct-hist.cc --- 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; }