Fix for a bug in OpenBSD vi
Jeffrey Johnson <[email protected]>
| Newsgroups | gmane.os.openbsd.bugs |
|---|---|
| Message-ID | <CA+-LWDCwrPWEZNKtGYX3yRHiUM=uT3dgV23+VG_nwiLOQYHqQA@mail.gmail.com> |
Greetings -
There is a bug in OpenBSD vi (that also exists in nvi, nvi2, and
OpenVi which is derived from OpenBSD vi) where screen corruption
results when using completion if line numbering is enabled.
See https://github.com/lichray/nvi2/issues/104 and
https://github.com/johnsonjh/OpenVi/issues/4 for a completion
description of the problem and steps to reproduce.
Patch to fix this issue follows, also attached as `vi.diff`:
```diff
diff --git a/usr.bin/vi/vi/v_txt.c b/usr.bin/vi/vi/v_txt.c
index 32845f7f81e..ec919741ac4 100644
--- a/usr.bin/vi/vi/v_txt.c
+++ b/usr.bin/vi/vi/v_txt.c
@@ -469,29 +469,36 @@ newtp: if ((tp = text_init(sp, lp,
len, len + 32)) == NULL)
next: if (v_event_get(sp, evp, 0, ec_flags))
return (1);
/*
* If file completion overwrote part of the screen and nothing else has
* been displayed, clean up. We don't do this as part of the normal
* message resolution because we know the user is on the colon command
* line and there's no reason to enter explicit characters to continue.
*/
if (filec_redraw && !F_ISSET(sp, SC_SCR_EXWROTE)) {
+ int stinput;
+
filec_redraw = 0;
fc.e_event = E_REPAINT;
fc.e_flno = vip->totalcount >=
sp->rows ? 1 : sp->rows - vip->totalcount;
fc.e_tlno = sp->rows;
vip->linecount = vip->lcontinue = vip->totalcount = 0;
+ stinput = F_ISSET(sp, SC_TINPUT_INFO);
+ if (stinput)
+ F_CLR(sp, SC_TINPUT_INFO);
(void)vs_repaint(sp, &fc);
(void)vs_refresh(sp, 1);
+ if (stinput)
+ F_SET(sp, SC_TINPUT_INFO);
}
/* Deal with all non-character events. */
switch (evp->e_event) {
case E_CHARACTER:
break;
case E_ERR:
case E_EOF:
F_SET(sp, SC_EXIT_FORCE);
return (1);
```
--
Jeffrey H. Johnson
[email protected]
vi.diff
(text/x-patch, 1.2 KB)
diff --git a/usr.bin/vi/vi/v_txt.c b/usr.bin/vi/vi/v_txt.c
index 32845f7f81e..ec919741ac4 100644
--- a/usr.bin/vi/vi/v_txt.c
+++ b/usr.bin/vi/vi/v_txt.c
@@ -469,29 +469,36 @@ newtp: if ((tp = text_init(sp, lp, len, len + 32)) == NULL)
next: if (v_event_get(sp, evp, 0, ec_flags))
return (1);
/*
* If file completion overwrote part of the screen and nothing else has
* been displayed, clean up. We don't do this as part of the normal
* message resolution because we know the user is on the colon command
* line and there's no reason to enter explicit characters to continue.
*/
if (filec_redraw && !F_ISSET(sp, SC_SCR_EXWROTE)) {
+ int stinput;
+
filec_redraw = 0;
fc.e_event = E_REPAINT;
fc.e_flno = vip->totalcount >=
sp->rows ? 1 : sp->rows - vip->totalcount;
fc.e_tlno = sp->rows;
vip->linecount = vip->lcontinue = vip->totalcount = 0;
+ stinput = F_ISSET(sp, SC_TINPUT_INFO);
+ if (stinput)
+ F_CLR(sp, SC_TINPUT_INFO);
(void)vs_repaint(sp, &fc);
(void)vs_refresh(sp, 1);
+ if (stinput)
+ F_SET(sp, SC_TINPUT_INFO);
}
/* Deal with all non-character events. */
switch (evp->e_event) {
case E_CHARACTER:
break;
case E_ERR:
case E_EOF:
F_SET(sp, SC_EXIT_FORCE);
return (1);