Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix infinite loop in emacs mode when HISTFILE is empty (#701)
This commit fixes a regression introduced in 5eeeed0. Pressing the up arrow in emacs mode when the history file is empty or otherwise cannot be accessed causes an infinite loop that repeatedly calls beep(). Reproducer (using /dev/null as HISTFILE also reproduces the bug): echo '' > /tmp/a; ENV=/dev/null HISTFILE=/tmp/a ksh -o emacs <Press Up Arrow> The loop happens because when blanks lines in the history file are skipped at L700, ed_ungetchar loops back to L635, beeps at L650, and since ksh is compiled with ESH_NFIRST enabled by default a goto at L655 jumps back to the code the initial ed_ungetchar is located. Since the variable c is still ^P, this loop continues into perpetuity. (Also of note is that if the history is not empty, but the first command is a blank space, ksh will loop once that space is reached while using the up arrow.) src/cmd/ksh93/edit/emacs.c: - Rather than use a goto that loops repeatedly, remove the ifndef that prevented use of the continue statement. Once the beep occurs we evidently can't go back any further in the command history, so bail out.
- Loading branch information