summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-05-24 19:59:51 +0200
committerBram Moolenaar <Bram@vim.org>2016-05-24 19:59:51 +0200
commit2b2b8ae5ab37b04584633c469265d85825166905 (patch)
tree735cc419532a905add4c9c3518976c7152b464a1
parenta57024453115592b8847af40ddd965a33898e390 (diff)
patch 7.4.1841v7.4.1841
Problem: The code to reallocate the buffer used for quickfix is repeated. Solution: Move the code to a function. (Yegappan Lakshmanan, closes #831)
-rw-r--r--src/quickfix.c85
-rw-r--r--src/testdir/test_quickfix.vim13
-rw-r--r--src/version.c2
3 files changed, 50 insertions, 50 deletions
diff --git a/src/quickfix.c b/src/quickfix.c
index 7b6d1bc9ce..a719e4fe0a 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -179,6 +179,31 @@ qf_init(
*/
#define LINE_MAXLEN 4096
+ static char_u *
+qf_grow_linebuf(char_u **growbuf, int *growbufsiz, int newsz, int *allocsz)
+{
+ /*
+ * If the line exceeds LINE_MAXLEN exclude the last
+ * byte since it's not a NL character.
+ */
+ *allocsz = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz;
+ if (*growbuf == NULL)
+ {
+ *growbuf = alloc(*allocsz + 1);
+ if (*growbuf == NULL)
+ return NULL;
+ *growbufsiz = *allocsz;
+ }
+ else if (*allocsz > *growbufsiz)
+ {
+ *growbuf = vim_realloc(*growbuf, *allocsz + 1);
+ if (*growbuf == NULL)
+ return NULL;
+ *growbufsiz = *allocsz;
+ }
+ return *growbuf;
+}
+
/*
* Read the errorfile "efile" into memory, line by line, building the error
* list.
@@ -538,24 +563,10 @@ qf_init_ext(
if (len > IOSIZE - 2)
{
- /*
- * If the line exceeds LINE_MAXLEN exclude the last
- * byte since it's not a NL character.
- */
- linelen = len > LINE_MAXLEN ? LINE_MAXLEN - 1 : len;
- if (growbuf == NULL)
- {
- growbuf = alloc(linelen + 1);
- growbufsiz = linelen;
- }
- else if (linelen > growbufsiz)
- {
- growbuf = vim_realloc(growbuf, linelen + 1);
- if (growbuf == NULL)
- goto qf_init_end;
- growbufsiz = linelen;
- }
- linebuf = growbuf;
+ linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len,
+ &linelen);
+ if (linebuf == NULL)
+ goto qf_init_end;
}
else
{
@@ -584,22 +595,10 @@ qf_init_ext(
len = (int)STRLEN(p_li->li_tv.vval.v_string);
if (len > IOSIZE - 2)
{
- linelen = len;
- if (linelen > LINE_MAXLEN)
- linelen = LINE_MAXLEN - 1;
- if (growbuf == NULL)
- {
- growbuf = alloc(linelen + 1);
- growbufsiz = linelen;
- }
- else if (linelen > growbufsiz)
- {
- if ((growbuf = vim_realloc(growbuf,
- linelen + 1)) == NULL)
- goto qf_init_end;
- growbufsiz = linelen;
- }
- linebuf = growbuf;
+ linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len,
+ &linelen);
+ if (linebuf == NULL)
+ goto qf_init_end;
}
else
{
@@ -621,20 +620,10 @@ qf_init_ext(
linelen = (int)STRLEN(p_buf);
if (linelen > IOSIZE - 2)
{
- if (growbuf == NULL)
- {
- growbuf = alloc(linelen + 1);
- growbufsiz = linelen;
- }
- else if (linelen > growbufsiz)
- {
- if (linelen > LINE_MAXLEN)
- linelen = LINE_MAXLEN - 1;
- if ((growbuf = vim_realloc(growbuf, linelen + 1)) == NULL)
- goto qf_init_end;
- growbufsiz = linelen;
- }
- linebuf = growbuf;
+ linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len,
+ &linelen);
+ if (linebuf == NULL)
+ goto qf_init_end;
}
else
linebuf = IObuff;
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 31ae9df4d7..e002303601 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -700,14 +700,14 @@ endfunc
" Tests for the setqflist() and setloclist() functions
function SetXlistTests(cchar, bnum)
+ let Xwindow = a:cchar . 'window'
+ let Xnext = a:cchar . 'next'
if a:cchar == 'c'
let Xsetlist = function('setqflist')
let Xgetlist = function('getqflist')
- let Xnext = 'cnext'
else
let Xsetlist = function('setloclist', [0])
let Xgetlist = function('getloclist', [0])
- let Xnext = 'lnext'
endif
call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
@@ -723,6 +723,15 @@ function SetXlistTests(cchar, bnum)
exe Xnext
call assert_equal(3, line('.'))
+ " Appending entries to the list should not change the cursor position
+ " in the quickfix window
+ exe Xwindow
+ 1
+ call Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
+ \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
+ call assert_equal(1, line('.'))
+ close
+
call Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
\ {'bufnr': a:bnum, 'lnum': 4},
\ {'bufnr': a:bnum, 'lnum': 5}], 'r')
diff --git a/src/version.c b/src/version.c
index eda517ace2..9e31e77321 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1841,
+/**/
1840,
/**/
1839,