mirror of
https://github.com/troglobit/editline.git
synced 2025-05-06 04:21:24 +08:00
Fix negative array index triggered by i-search
This is a fix to a bug reported by Claus Fischer. When doing a reversed i-search on the history, clear_line() sets rl_point to a negative value, which is later used by ceol(). The intention is to clear the whole line for the new Search: prompt, but indexing an array with a negative value is strongly discouraged. To prevent this negative indexing from happening we check in ceol() for rl_point < 0, but we quickly notice another side effect: one lingering character at the end of line when returning from i-search. The problem manifests itself more cleary when having a looooo000ooonong prompt. The fix is to rub out the extra space, insert the i-search string, and *then* call ceol() again. Thanks to Claus for pointing this out! Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
91937d970d
commit
2a3b422137
@ -431,11 +431,17 @@ static el_status_t case_cap_word(void)
|
|||||||
|
|
||||||
static void ceol(void)
|
static void ceol(void)
|
||||||
{
|
{
|
||||||
int extras;
|
int extras = 0;
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
for (extras = 0, i = rl_point, p = &rl_line_buffer[i]; i <= rl_end; i++, p++) {
|
while (rl_point < 0) {
|
||||||
|
tty_put(' ');
|
||||||
|
rl_point++;
|
||||||
|
extras++;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = rl_point, p = &rl_line_buffer[i]; i <= rl_end; i++, p++) {
|
||||||
tty_put(' ');
|
tty_put(' ');
|
||||||
if (ISMETA(*p)) {
|
if (ISMETA(*p)) {
|
||||||
if (rl_meta_chars) {
|
if (rl_meta_chars) {
|
||||||
@ -443,7 +449,7 @@ static void ceol(void)
|
|||||||
tty_put(' ');
|
tty_put(' ');
|
||||||
extras += 2;
|
extras += 2;
|
||||||
}
|
}
|
||||||
} if (ISCTL(*p)) {
|
} else if (ISCTL(*p)) {
|
||||||
tty_put(' ');
|
tty_put(' ');
|
||||||
extras++;
|
extras++;
|
||||||
}
|
}
|
||||||
@ -525,15 +531,19 @@ static const char *prev_hist(void)
|
|||||||
|
|
||||||
static el_status_t do_insert_hist(const char *p)
|
static el_status_t do_insert_hist(const char *p)
|
||||||
{
|
{
|
||||||
|
el_status_t ret;
|
||||||
|
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return el_ring_bell();
|
return el_ring_bell();
|
||||||
|
|
||||||
rl_point = 0;
|
rl_point = 0;
|
||||||
reposition();
|
reposition();
|
||||||
ceol();
|
|
||||||
rl_end = 0;
|
rl_end = 0;
|
||||||
|
|
||||||
return insert_string(p);
|
ret = insert_string(p);
|
||||||
|
ceol();
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static el_status_t do_hist(const char *(*move)(void))
|
static el_status_t do_hist(const char *(*move)(void))
|
||||||
|
Loading…
Reference in New Issue
Block a user