[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH v2] vi: Ensure that the edit buffer ends in a newline
From: Petja Patjas <pp01415943 () gmail ! com>
Date: 2023-04-17 13:28:53
Message-ID: 20230417132853.46391-1-pp01415943 () gmail ! com
[Download RAW message or body]
Currently vi assumes that the edit buffer ends in a newline. This may
not be the case. For example:
$ printf test > test
$ vi test
<press 'o'>
We fix this by inserting a newline to the end during initialization.
Signed-off-by: Petja Patjas <pp01415943@gmail.com>
---
The first patch didn't apply, sorry about that. I also took this chance
to simplify the logic a bit.
editors/vi.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/editors/vi.c b/editors/vi.c
index 2645afe87..2947c5c1b 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2315,9 +2315,10 @@ static int init_text_buffer(char *fn)
update_filename(fn);
rc = file_insert(fn, text, 1);
- if (rc < 0) {
- // file doesnt exist. Start empty buf with dummy line
- char_insert(text, '\n', NO_UNDO);
+ if (rc <= 0 || *(end - 1) != '\n') {
+ // file doesn't exist or doesn't end in a newline.
+ // insert a newline to the end
+ char_insert(end, '\n', NO_UNDO);
}
flush_undo_data();
--
2.40.0
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic