aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetja Patjas <pp01415943@gmail.com>2023-04-17 16:28:53 +0300
committerDenys Vlasenko <vda.linux@googlemail.com>2024-07-11 17:52:18 +0200
commit05e5d6a38157cabc733fc30acf3646a099cf139c (patch)
tree148f7f13fda4018543ef21257dd6925be049884d
parent0af28b84e58307422f807ddbdafc67a68f71eb64 (diff)
downloadbusybox-w32-05e5d6a38157cabc733fc30acf3646a099cf139c.tar.gz
busybox-w32-05e5d6a38157cabc733fc30acf3646a099cf139c.tar.bz2
busybox-w32-05e5d6a38157cabc733fc30acf3646a099cf139c.zip
vi: Ensure that the edit buffer ends in a newline
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> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/vi.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 3cc3d2a0b..34932f60c 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2315,9 +2315,10 @@ static int init_text_buffer(char *fn)
2315 2315
2316 update_filename(fn); 2316 update_filename(fn);
2317 rc = file_insert(fn, text, 1); 2317 rc = file_insert(fn, text, 1);
2318 if (rc < 0) { 2318 if (rc <= 0 || *(end - 1) != '\n') {
2319 // file doesnt exist. Start empty buf with dummy line 2319 // file doesn't exist or doesn't end in a newline.
2320 char_insert(text, '\n', NO_UNDO); 2320 // insert a newline to the end
2321 char_insert(end, '\n', NO_UNDO);
2321 } 2322 }
2322 2323
2323 flush_undo_data(); 2324 flush_undo_data();