Patch 8.1.2269

28 views
Skip to first unread message

Bram Moolenaar

unread,
Nov 7, 2019, 5:09:38 PM11/7/19
to vim...@googlegroups.com

Patch 8.1.2269
Problem: Tags file with very long line stops using binary search.
Solution: Reallocate the buffer if needed.
Files: src/tag.c, src/testdir/test_tagjump.vim


*** ../vim-8.1.2268/src/tag.c 2019-10-18 20:53:30.697741631 +0200
--- src/tag.c 2019-11-07 23:06:28.181634266 +0100
***************
*** 1937,1943 ****
*/
else if (state == TS_SKIP_BACK)
{
! search_info.curr_offset -= LSIZE * 2;
if (search_info.curr_offset < 0)
{
search_info.curr_offset = 0;
--- 1937,1943 ----
*/
else if (state == TS_SKIP_BACK)
{
! search_info.curr_offset -= lbuf_size * 2;
if (search_info.curr_offset < 0)
{
search_info.curr_offset = 0;
***************
*** 1955,1961 ****
/* Adjust the search file offset to the correct position */
search_info.curr_offset_used = search_info.curr_offset;
vim_fseek(fp, search_info.curr_offset, SEEK_SET);
! eof = vim_fgets(lbuf, LSIZE, fp);
if (!eof && search_info.curr_offset != 0)
{
/* The explicit cast is to work around a bug in gcc 3.4.2
--- 1955,1961 ----
/* Adjust the search file offset to the correct position */
search_info.curr_offset_used = search_info.curr_offset;
vim_fseek(fp, search_info.curr_offset, SEEK_SET);
! eof = vim_fgets(lbuf, lbuf_size, fp);
if (!eof && search_info.curr_offset != 0)
{
/* The explicit cast is to work around a bug in gcc 3.4.2
***************
*** 1967,1979 ****
vim_fseek(fp, search_info.low_offset, SEEK_SET);
search_info.curr_offset = search_info.low_offset;
}
! eof = vim_fgets(lbuf, LSIZE, fp);
}
/* skip empty and blank lines */
while (!eof && vim_isblankline(lbuf))
{
search_info.curr_offset = vim_ftell(fp);
! eof = vim_fgets(lbuf, LSIZE, fp);
}
if (eof)
{
--- 1967,1979 ----
vim_fseek(fp, search_info.low_offset, SEEK_SET);
search_info.curr_offset = search_info.low_offset;
}
! eof = vim_fgets(lbuf, lbuf_size, fp);
}
/* skip empty and blank lines */
while (!eof && vim_isblankline(lbuf))
{
search_info.curr_offset = vim_ftell(fp);
! eof = vim_fgets(lbuf, lbuf_size, fp);
}
if (eof)
{
***************
*** 1996,2005 ****
{
#ifdef FEAT_CSCOPE
if (use_cscope)
! eof = cs_fgets(lbuf, LSIZE);
else
#endif
! eof = vim_fgets(lbuf, LSIZE, fp);
} while (!eof && vim_isblankline(lbuf));

if (eof)
--- 1996,2005 ----
{
#ifdef FEAT_CSCOPE
if (use_cscope)
! eof = cs_fgets(lbuf, lbuf_size);
else
#endif
! eof = vim_fgets(lbuf, lbuf_size, fp);
} while (!eof && vim_isblankline(lbuf));

if (eof)
***************
*** 2230,2257 ****
// When the line is too long the NUL will not be in the
// last-but-one byte (see vim_fgets()).
// Has been reported for Mozilla JS with extremely long names.
! // In that case we can't parse it and we ignore the line.
! if (lbuf[LSIZE - 2] != NUL
#ifdef FEAT_CSCOPE
&& !use_cscope
#endif
)
{
! if (p_verbose >= 5)
! {
! verbose_enter();
! msg(_("Ignoring long line in tags file"));
! verbose_leave();
! }
! #ifdef FEAT_TAG_BINS
! if (state != TS_LINEAR)
! {
! // Avoid getting stuck.
! linear = TRUE;
! state = TS_LINEAR;
! vim_fseek(fp, search_info.low_offset, SEEK_SET);
! }
! #endif
continue;
}

--- 2230,2250 ----
// When the line is too long the NUL will not be in the
// last-but-one byte (see vim_fgets()).
// Has been reported for Mozilla JS with extremely long names.
! // In that case we need to increase lbuf_size.
! if (lbuf[lbuf_size - 2] != NUL
#ifdef FEAT_CSCOPE
&& !use_cscope
#endif
)
{
! lbuf_size *= 2;
! vim_free(lbuf);
! lbuf = alloc(lbuf_size);
! if (lbuf == NULL)
! goto findtag_end;
! // this will try the same thing again, make sure the offset is
! // different
! search_info.curr_offset = 0;
continue;
}

***************
*** 3367,3372 ****
--- 3360,3367 ----
break;
#endif
*pbuf_end++ = *str++;
+ if (pbuf_end - pbuf + 1 >= LSIZE)
+ break;
}
*pbuf_end = NUL;

*** ../vim-8.1.2268/src/testdir/test_tagjump.vim 2019-10-12 20:17:24.605773312 +0200
--- src/testdir/test_tagjump.vim 2019-11-07 22:57:01.051787724 +0100
***************
*** 459,465 ****
call assert_report(v:exception)
catch /.*/
endtry
! call assert_equal('Ignoring long line in tags file', split(execute('messages'), '\n')[-1])
call writefile([
\ '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 django/contrib/admin/templates/admin/edit_inline/stacked.html 16;" j line:16 language:HTML'
\ ], 'Xtags')
--- 459,466 ----
call assert_report(v:exception)
catch /.*/
endtry
! call assert_equal('Searching tags file Xtags', split(execute('messages'), '\n')[-1])
!
call writefile([
\ '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 django/contrib/admin/templates/admin/edit_inline/stacked.html 16;" j line:16 language:HTML'
\ ], 'Xtags')
***************
*** 470,477 ****
call assert_report(v:exception)
catch /.*/
endtry
! call assert_equal('Ignoring long line in tags file', split(execute('messages'), '\n')[-1])
call delete('Xtags')
set tags&
let &verbose = old_vbs
endfunc
--- 471,496 ----
call assert_report(v:exception)
catch /.*/
endtry
! call assert_equal('Searching tags file Xtags', split(execute('messages'), '\n')[-1])
!
! " binary search works in file with long line
! call writefile([
! \ 'asdfasfd nowhere 16',
! \ 'foobar Xsomewhere 3; " 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567',
! \ 'zasdfasfd nowhere 16',
! \ ], 'Xtags')
! call writefile([
! \ 'one',
! \ 'two',
! \ 'trhee',
! \ 'four',
! \ ], 'Xsomewhere')
! tag foobar
! call assert_equal('Xsomewhere', expand('%'))
! call assert_equal(3, getcurpos()[1])
!
call delete('Xtags')
+ call delete('Xsomewhere')
set tags&
let &verbose = old_vbs
endfunc
*** ../vim-8.1.2268/src/version.c 2019-11-07 20:48:38.729213691 +0100
--- src/version.c 2019-11-07 22:25:55.118872708 +0100
***************
*** 743,744 ****
--- 743,746 ----
{ /* Add new patch number below this line */
+ /**/
+ 2269,
/**/

--
Never overestimate a man's ability to underestimate a woman.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christ van Willegen

unread,
Nov 7, 2019, 5:16:03 PM11/7/19
to vim...@googlegroups.com


Op do 7 nov. 2019 23:09 schreef Bram Moolenaar <Br...@moolenaar.net>:

Patch 8.1.2269


***************
*** 3367,3372 ****
--- 3360,3367 ----
            break;
  #endif
        *pbuf_end++ = *str++;
+       if (pbuf_end - pbuf + 1 >= LSIZE)
+           break;

Not >= lbuf_size?

Christ van Willegen 

Bram Moolenaar

unread,
Nov 8, 2019, 10:50:55 AM11/8/19
to vim...@googlegroups.com, Christ van Willegen
pbuf is allocated with LSIZE. It's only for the command, thus I assume
we don't need it to be bigger. Also because lbuf_size is not available
here.

--
I started out with nothing, and I still have most of it.
-- Michael Davis -- "Tonight Show"

John Marriott

unread,
Nov 8, 2019, 1:50:29 PM11/8/19
to vim...@googlegroups.com

On 08-Nov-2019 09:09, Bram Moolenaar wrote:
> Patch 8.1.2269
> Problem: Tags file with very long line stops using binary search.
> Solution: Reallocate the buffer if needed.
> Files: src/tag.c, src/testdir/test_tagjump.vim
>
Hi All,

After this patch, mingw64 (gcc 9.2.1) spits out this error if
FEAT_TAG_BINS is not defined:
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -DFEAT_GUI_MSWIN
-DFEAT_CLIPBOARD -pipe -march=native -Wall -O3 -fomit-frame-pointer
-freg-struct-return tag.c -o gobjnative/tag.o
tag.c: In function 'find_tags':
tag.c:2247:3: error: 'search_info' undeclared (first use in this
function); did you mean 'searchit'?
 2247 |   search_info.curr_offset = 0;
      |   ^~~~~~~~~~~
      |   searchit
tag.c:2247:3: note: each undeclared identifier is reported only once for
each function it appears in
make: *** [Make_cyg_ming.mak:1104: gobjnative/tag.o] Error 1
make: Target 'gvim.exe' not remade because of errors.

I'm not sure how to fix it though.
Cheers
John

Bram Moolenaar

unread,
Nov 8, 2019, 3:57:32 PM11/8/19
to vim...@googlegroups.com, John Marriott
Adding an #ifdef will fix it.

However, I wonder why you build without FEAT_TAG_BINS. That's really
only for when using EBCDIC (VMS build), then sorting won't work.

--
hundred-and-one symptoms of being an internet addict:
40. You tell the cab driver you live at
http://123.elm.street/house/bluetrim.html
41. You actually try that 123.elm.street address.

John Marriott

unread,
Nov 8, 2019, 4:15:47 PM11/8/19
to vim...@googlegroups.com


On 09-Nov-2019 07:57, Bram Moolenaar wrote:
>
> However, I wonder why you build without FEAT_TAG_BINS. That's really
> only for when using EBCDIC (VMS build), then sorting won't work.
>
I like turning things on/off to see what breaks. :-)
Reply all
Reply to author
Forward
0 new messages