From 829afbd150936f188a9488e7ba8180db95a2be87 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 17 Mar 2019 09:57:29 +0000 Subject: 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. --- editors/vi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'editors/vi.c') 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) status_line_bold_errno(fn); p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert } else if (cnt < size) { +#if ENABLE_PLATFORM_MINGW32 + // On WIN32 a partial read might just mean CRs have been removed + int cnt_cr = cnt + count_cr(p, cnt); +#endif // There was a partial read, shrink unused space p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO); #if ENABLE_PLATFORM_MINGW32 - // On WIN32 a partial read might just mean CRs have been removed - if (cnt + count_cr(p, cnt) < size) + if (cnt_cr < size) #endif status_line_bold("can't read '%s'", fn); } -- cgit v1.2.3-55-g6feb