aboutsummaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-03-17 09:57:29 +0000
committerRon Yorston <rmy@pobox.com>2019-03-17 09:57:29 +0000
commit829afbd150936f188a9488e7ba8180db95a2be87 (patch)
treea9423608da524978b1f2b28458985b62682c4ada /editors/vi.c
parent7f8036d3f0f599a10090c22b73126b7ec6ee3727 (diff)
downloadbusybox-w32-829afbd150936f188a9488e7ba8180db95a2be87.tar.gz
busybox-w32-829afbd150936f188a9488e7ba8180db95a2be87.tar.bz2
busybox-w32-829afbd150936f188a9488e7ba8180db95a2be87.zip
vi: fix spurious error on opening file with CRLF line endings
Commit 91e49fbc7 (vi: add a function to count CRs in the text buffer) resulted in the spurious error "can't read 'file'" when opening a file with CRLF line endings. This was because the count function was called with an incorrect pointer into the text buffer. The upstream code: p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO); unnecessarily updates the pointer p: it's never used again.
Diffstat (limited to 'editors/vi.c')
-rw-r--r--editors/vi.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/editors/vi.c b/editors/vi.c
index da5f0a8c3..15ebe8dae 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2989,11 +2989,14 @@ static int file_insert(const char *fn, char *p, int initial)
2989 status_line_bold_errno(fn); 2989 status_line_bold_errno(fn);
2990 p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert 2990 p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert
2991 } else if (cnt < size) { 2991 } else if (cnt < size) {
2992#if ENABLE_PLATFORM_MINGW32
2993 // On WIN32 a partial read might just mean CRs have been removed
2994 int cnt_cr = cnt + count_cr(p, cnt);
2995#endif
2992 // There was a partial read, shrink unused space 2996 // There was a partial read, shrink unused space
2993 p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO); 2997 p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO);
2994#if ENABLE_PLATFORM_MINGW32 2998#if ENABLE_PLATFORM_MINGW32
2995 // On WIN32 a partial read might just mean CRs have been removed 2999 if (cnt_cr < size)
2996 if (cnt + count_cr(p, cnt) < size)
2997#endif 3000#endif
2998 status_line_bold("can't read '%s'", fn); 3001 status_line_bold("can't read '%s'", fn);
2999 } 3002 }