Skip to content

Commit 2e9f3a1

Browse files
Handle out-of-band lines in expandtab (#154)
The procedure that causes the bug: * open vi with set expandtab * yy -> yank something * :di b -> shows that the default buffer have the text copied * :!ls >/dev/null run an external command without filtering lines, all commands are the same * :di b -> already shows something strange, outputting: ********** default buffer (character mode) note that when the buffers are empty :di b shows: No cut buffers to display. * p -> trying to paste segfault A bug that does not segfault occurs also with the bang command, but when filtering lines: * open vi with set expandtab * yy -> yank something and then move to an other line * :di b -> shows that the default buffer have the text copied * :.!ls >/dev/null run an external command filtering any range of lines, both one address or two is the same, noticing the content of the line you are on * :di b -> shows that the line(s) being put into the default buffer is(are) the line(s) that is(are) now under the cursor, not the original deleted ones Running the bang without filtering files leaves the sp->gp->dcb_store as a dangling pointer. Closes: #151 Co-authored-by: Jerry Fletcher <mail@jerryfletcher.org>
1 parent 99779b8 commit 2e9f3a1

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

common/cut.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ cut(SCR *sp, CHAR_T *namep, MARK *fm, MARK *tm, int flags)
6868
recno_t lno;
6969
int append, copy_one, copy_def;
7070

71+
/* Check if the line numbers are out-of-band */
72+
if (fm->lno == OOBLNO || tm->lno == OOBLNO)
73+
return (1);
74+
7175
/*
7276
* If the user specified a buffer, put it there. (This may require
7377
* a copy into the numeric buffers. We do the copy so that we don't
@@ -175,6 +179,7 @@ namecb: CBNAME(sp, cbp, name);
175179
text_lfree(cbp->textq);
176180
cbp->len = 0;
177181
cbp->flags = 0;
182+
sp->gp->dcbp = NULL;
178183
return (1);
179184
}
180185

common/line.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ db_eget(SCR *sp,
5151
* line in an empty file, find the last line of the file; db_last
5252
* fails loudly.
5353
*/
54-
if ((lno == 0 || lno == 1) && db_last(sp, &l1))
54+
if ((lno == OOBLNO || lno == 1) && db_last(sp, &l1))
5555
return (1);
5656

5757
/* If the file isn't empty, fail loudly. */
@@ -92,7 +92,7 @@ db_get(SCR *sp,
9292
* have to have an OOB condition for the look-aside into the input
9393
* buffer anyway.
9494
*/
95-
if (lno == 0)
95+
if (lno == OOBLNO)
9696
goto err1;
9797

9898
/* Check for no underlying file. */

ex/ex_bang.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ ex_bang(SCR *sp, EXCMD *cmdp)
174174
if (!F_ISSET(sp, SC_VI) && !F_ISSET(sp, SC_EX_SILENT))
175175
(void)ex_puts(sp, "!\n");
176176

177-
/* Apply expandtab to the new text */
178-
if (O_ISSET(sp, O_EXPANDTAB))
177+
/* If addresses were specified, apply expandtab to the new text */
178+
if (cmdp->addrcnt != 0 && O_ISSET(sp, O_EXPANDTAB))
179179
ex_retab(sp, cmdp);
180180

181181
/*

ex/ex_shift.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ shift(SCR *sp, EXCMD *cmdp, enum which rl)
7979
return (0);
8080
}
8181

82-
/* Copy the lines being shifted into the unnamed buffer. */
83-
if (cut(sp, NULL, &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE))
82+
/*
83+
* When not doing re-expand tabs, copy the lines being shifted into
84+
* the unnamed buffer.
85+
*/
86+
if (rl != RETAB &&
87+
cut(sp, NULL, &cmdp->addr1, &cmdp->addr2, CUT_LINEMODE))
8488
return (1);
8589

8690
/*

0 commit comments

Comments
 (0)