aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-12-05 14:58:44 +0000
committerRon Yorston <rmy@pobox.com>2014-12-05 14:58:44 +0000
commitd143657a79e250bdb91dff9a90d882c95f4b94a2 (patch)
tree531553607d1ab74de95e44e119e0ca93ca690789
parent3ddafae731eaede5795f519e04ec40dcd44aae92 (diff)
downloadbusybox-w32-d143657a79e250bdb91dff9a90d882c95f4b94a2.tar.gz
busybox-w32-d143657a79e250bdb91dff9a90d882c95f4b94a2.tar.bz2
busybox-w32-d143657a79e250bdb91dff9a90d882c95f4b94a2.zip
vi: fix reading of file after last line
If the :r command is used to read a file after the last line of the buffer the last line of the buffer and the first line of the file are joined. An extra blank line appears at the end of the buffer. file 1 file 1 file 1file 2 file 2 file 2 ~ ~ The insertion point is normally at the start of the line following the specified line. When the specified line is the last one the next_line function baulks at moving to the non-existent following line.
-rw-r--r--editors/vi.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 84da6db74..1fa97b568 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1318,8 +1318,12 @@ static void colon(char *buf)
1318 q = begin_line(dot); // assume "dot" 1318 q = begin_line(dot); // assume "dot"
1319 } 1319 }
1320 // read after current line- unless user said ":0r foo" 1320 // read after current line- unless user said ":0r foo"
1321 if (b != 0) 1321 if (b != 0) {
1322 q = next_line(q); 1322 q = next_line(q);
1323 // read after last line
1324 if (q == end-1)
1325 ++q;
1326 }
1323 { // dance around potentially-reallocated text[] 1327 { // dance around potentially-reallocated text[]
1324 uintptr_t ofs = q - text; 1328 uintptr_t ofs = q - text;
1325 size = file_insert(fn, q, 0); 1329 size = file_insert(fn, q, 0);