7 Bug-Reported-by: <piuma@piumalab.org>
8 Bug-Reference-ID: <4DAAC0DB.7060606@piumalab.org>
9 Bug-Reference-URL: http://lists.gnu.org/archive/html/bug-bash/2011-04/msg00075.html
13 Under certain circumstances, running `fc -l' two times in succession with a
14 relative history offset at the end of the history will result in an incorrect
15 calculation of the last history entry and a seg fault.
17 Patch (apply with `patch -p0'):
21 @@ -304,7 +304,7 @@ fc_builtin (list)
22 last_hist = i - rh - hist_last_line_added;
25 - if (saved_command_line_count > 0 && i == last_hist && hlist[last_hist] == 0)
26 + if (i == last_hist && hlist[last_hist] == 0)
27 while (last_hist >= 0 && hlist[last_hist] == 0)
30 @@ -475,7 +475,7 @@ fc_gethnum (command, hlist)
33 int sign, n, clen, rh;
35 + register int i, j, last_hist;
39 @@ -495,7 +495,15 @@ fc_gethnum (command, hlist)
40 has been enabled (interactive or not) should use it in the last_hist
41 calculation as if it were on. */
42 rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
43 - i -= rh + hist_last_line_added;
44 + last_hist = i - rh - hist_last_line_added;
46 + if (i == last_hist && hlist[last_hist] == 0)
47 + while (last_hist >= 0 && hlist[last_hist] == 0)
54 /* No specification defaults to most recent command. */
59 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
60 looks for to find the patch level (for the sccs version string). */
65 #endif /* _PATCHLEVEL_H_ */