Loading ...
Sorry, an error occurred while loading the content.

15996[patch] bug in syntax folding when using :syn sync fromstart

Expand Messages
  • Utz-Uwe Haus
    Nov 1, 2000
      Hi,

      while using the fresh version 6.0k this morning I came across a buglet
      in syn_sync(). To reproduce try editing, for example vim's top-level
      Makefile, then type
      :syn sync fromstart

      I immediately get a 'ml_get(): invalid lnum:' error with a number that
      looks almost like MAX_INT. The reason is that syncing from start sets
      syn_buf->b_syn_sync_minlines to MAXLNUM, and the code in syn_sync()
      assumes it can do

      start_lnum -= syn_buf->b_syn_sync_minlines + 10;

      without overflow.

      Fix included; could probably be more beautiful but 'works for me' (tm).

      Later
      Utz

      ----- cut here -----
      Index: syntax.c
      ===================================================================
      RCS file: /cvsroot/vim/vim/src/syntax.c,v
      retrieving revision 1.18
      diff -u -c -r1.18 syntax.c
      cvs server: conflicting specifications of output style
      *** syntax.c 2000/10/29 22:50:27 1.18
      --- syntax.c 2000/11/01 14:16:30
      ***************
      *** 660,666 ****
      start_lnum -= syn_buf->b_syn_sync_minlines * 2;
      else
      start_lnum -= syn_buf->b_syn_sync_minlines + 10;
      ! if (start_lnum < 1)
      start_lnum = 1;
      current_lnum = start_lnum;

      --- 660,671 ----
      start_lnum -= syn_buf->b_syn_sync_minlines * 2;
      else
      start_lnum -= syn_buf->b_syn_sync_minlines + 10;
      ! /* start_lnum may be have passed the start, then set it to 1.
      ! * minlines+10 may also have overflowed signed int arithmetic, in that
      ! * case start_lnum is totally bogus. What we meant to do then was to start
      ! * from line 1 too, so there:
      ! */
      ! if (start_lnum < 1 || MAXLNUM-10 < syn_buf->b_syn_sync_minlines)
      start_lnum = 1;
      current_lnum = start_lnum;

      --------------------


      --
      Utz-Uwe Haus haus@...-magdeburg.de
      Inst. f. Math. Optim. utz@...
      Uni Magdeburg PGP keys 1024/6AD23BE1 and 2048/5D0B72A1
      GERMANY available via keyservers or email request
    • Show all 2 messages in this topic