bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

'history -p' bug -- patch


From: Neal Burns
Subject: 'history -p' bug -- patch
Date: Sun, 21 Sep 2003 21:42:14 -0700 (PDT)

I've included a patch for the segfault in 'history -p' I reported earlier
today in 2.05b. The problem can be reproduced by attempting any history
search with 'history -p', e.g.

$ history -p \!man

The problem is that the history builtin removes itself from the history
before searching (thus shortening the history), but doesn't update
history_offset, so history_offset winds up pointing off the end.

The fix follows.

Regards,

Neal Burns

P.S. Another apparent problem is that 'history -p' with no argument fails
silently. But I'll leave that one up to your discretion.

diff -Naur bash-2.05b-old/builtins/history.def bash-2.05b/builtins/history.def
--- bash-2.05b-old/builtins/history.def 2003-09-21 20:59:43.000000000 -0700
+++ bash-2.05b/builtins/history.def     2003-09-21 21:01:48.000000000 -0700
@@ -276,6 +276,7 @@
 {
   register int i;
   HIST_ENTRY **hlist, *histent;
+  int result;

   hlist = history_list ();
   if (hlist == NULL)
@@ -290,7 +291,13 @@
   if (histent == NULL)
     return 0;

-  return (delete_histent (i));
+  result = delete_histent (i);
+
+  /* this is needed because remove_history changes history_length */
+  if (where_history () > history_length)
+    history_set_pos (history_length);
+
+  return result;
 }

 /* Remove the last entry in the history list and add each argument in




reply via email to

[Prev in Thread] Current Thread [Next in Thread]