Hi,
If a file passed to the 'qf_init_ext' function contains lines longer
than 1021 bytes (might be platform specific) the rest of the line is
recognized as a separate error without a valid filename and lnum. If a
string or list is passed to 'qf_init_ext' the rest of a long line is
discarded. This patch adds the same behavior while reading errors from a
file. This is done by continue reading from the file in to a temporary
buffer until end-of-line is encountered. Could any existing general
purpose buffer with a known size be used instead of allocation a new
one?
--
:wq
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/alloc.h b/src/alloc.h
index 90a9878..f1a9bd2 100644
--- a/src/alloc.h
+++ b/src/alloc.h
@@ -17,5 +17,6 @@ typedef enum {
aid_qf_namebuf,
aid_qf_errmsg,
aid_qf_pattern,
+ aid_qf_discard,
aid_last
} alloc_id_T;
diff --git a/src/quickfix.c b/src/quickfix.c
index 00762bd..739fc89 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -198,6 +198,7 @@ qf_init_ext(
char_u *namebuf;
char_u *errmsg;
char_u *pattern;
+ char_u *discard;
char_u *fmtstr = NULL;
int col = 0;
char_u use_viscol = FALSE;
@@ -216,6 +217,7 @@ qf_init_ext(
char_u *efm;
char_u *ptr;
char_u *srcptr;
+ int buflen;
int len;
int i;
int round;
@@ -252,7 +254,8 @@ qf_init_ext(
namebuf = alloc_id(CMDBUFFSIZE + 1, aid_qf_namebuf);
errmsg = alloc_id(CMDBUFFSIZE + 1, aid_qf_errmsg);
pattern = alloc_id(CMDBUFFSIZE + 1, aid_qf_pattern);
- if (namebuf == NULL || errmsg == NULL || pattern == NULL)
+ discard = alloc_id(CMDBUFFSIZE + 1, aid_qf_discard);
+ if (namebuf == NULL || errmsg == NULL || pattern == NULL || discard ==
NULL)
goto qf_init_end;
if (efile != NULL && (fd = mch_fopen((char *)efile, "r")) == NULL)
@@ -557,8 +560,31 @@ qf_init_ext(
CMDBUFFSIZE - 2);
}
}
- else if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL)
- break;
+ else
+ {
+ if (fgets((char *)IObuff, CMDBUFFSIZE - 2, fd) == NULL)
+ break;
+
+ buflen = (int)STRLEN(IObuff);
+ while (buflen == CMDBUFFSIZE - 2 - 1)
+ {
+ /*
+ * End-of-line not yet reached since the number of read bytes is
+ * equal to the size of the buffer, excluding null-terminator.
+ * Continue reading and discard the rest of the line.
+ */
+ if (fgets((char *)discard, CMDBUFFSIZE - 2, fd) == NULL)
+ break;
+
+ buflen = (int)STRLEN(discard);
+ if (discard[buflen - 1] == '\n'
+#ifdef USE_CRNL
+ || discard[buflen - 1] == '\r'
+#endif
+ )
+ break;
+ }
+ }
IObuff[CMDBUFFSIZE - 2] = NUL; /* for very long lines */
#ifdef FEAT_MBYTE
@@ -878,6 +904,7 @@ qf_init_end:
vim_free(errmsg);
vim_free(pattern);
vim_free(fmtstr);
+ vim_free(discard);
#ifdef FEAT_WINDOWS
qf_update_buffer(qi);
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 8da1b6f..df2c0a0 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -697,3 +697,14 @@ func Test_cgetexpr_works()
" this must not crash Vim
cgetexpr [$x]
endfunc
+
+func Test_cgetfile_long_lines()
+ let tmp = tempname()
+ exe 'new' tmp
+ normal ifile:1:
+ normal $2000aa
+ w | bw
+ exe 'cgetfile' fnameescape(tmp)
+ call assert_equal(1, len(getqflist()))
+ call assert_true(len(getqflist()[0].text) < 2000)
+endfunc