Blob Blame History Raw
To: vim-dev@vim.org
Subject: Patch 7.1.162
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.1.162
Problem:    Crash when using a modifier before "while" or "for". (A.Politz)
Solution:   Skip modifiers when checking for a loop command.
Files:	    src/proto/ex_docmd.pro, src/ex_docmd.c, src/ex_eval.c


*** ../vim-7.1.161/src/proto/ex_docmd.pro	Sun Sep 30 14:00:41 2007
--- src/proto/ex_docmd.pro	Sat Nov 24 16:34:06 2007
***************
*** 5,10 ****
--- 5,11 ----
  int getline_equal __ARGS((char_u *(*fgetline)(int, void *, int), void *cookie, char_u *(*func)(int, void *, int)));
  void *getline_cookie __ARGS((char_u *(*fgetline)(int, void *, int), void *cookie));
  int checkforcmd __ARGS((char_u **pp, char *cmd, int len));
+ int modifier_len __ARGS((char_u *cmd));
  int cmd_exists __ARGS((char_u *name));
  char_u *set_one_cmd_context __ARGS((expand_T *xp, char_u *buff));
  char_u *skip_range __ARGS((char_u *cmd, int *ctx));
*** ../vim-7.1.161/src/ex_docmd.c	Tue Nov 20 12:30:31 2007
--- src/ex_docmd.c	Sat Nov 24 16:41:20 2007
***************
*** 2963,2968 ****
--- 2963,3019 ----
  #endif
  
  #if defined(FEAT_EVAL) || defined(PROTO)
+ static struct cmdmod
+ {
+     char	*name;
+     int		minlen;
+     int		has_count;  /* :123verbose  :3tab */
+ } cmdmods[] = {
+     {"aboveleft", 3, FALSE},
+     {"belowright", 3, FALSE},
+     {"botright", 2, FALSE},
+     {"browse", 3, FALSE},
+     {"confirm", 4, FALSE},
+     {"hide", 3, FALSE},
+     {"keepalt", 5, FALSE},
+     {"keepjumps", 5, FALSE},
+     {"keepmarks", 3, FALSE},
+     {"leftabove", 5, FALSE},
+     {"lockmarks", 3, FALSE},
+     {"rightbelow", 6, FALSE},
+     {"sandbox", 3, FALSE},
+     {"silent", 3, FALSE},
+     {"tab", 3, TRUE},
+     {"topleft", 2, FALSE},
+     {"verbose", 4, TRUE},
+     {"vertical", 4, FALSE},
+ };
+ 
+ /*
+  * Return length of a command modifier (including optional count).
+  * Return zero when it's not a modifier.
+  */
+     int
+ modifier_len(cmd)
+     char_u	*cmd;
+ {
+     int		i, j;
+     char_u	*p = cmd;
+ 
+     if (VIM_ISDIGIT(*cmd))
+ 	p = skipwhite(skipdigits(cmd));
+     for (i = 0; i < sizeof(cmdmods) / sizeof(struct cmdmod); ++i)
+     {
+ 	for (j = 0; p[j] != NUL; ++j)
+ 	    if (p[j] != cmdmods[i].name[j])
+ 		break;
+ 	if (!isalpha(p[j]) && j >= cmdmods[i].minlen
+ 					&& (p == cmd || cmdmods[i].has_count))
+ 	    return j + (p - cmd);
+     }
+     return 0;
+ }
+ 
  /*
   * Return > 0 if an Ex command "name" exists.
   * Return 2 if there is an exact match.
***************
*** 2977,3006 ****
      int		i;
      int		j;
      char_u	*p;
-     static struct cmdmod
-     {
- 	char	*name;
- 	int	minlen;
-     } cmdmods[] = {
- 	{"aboveleft", 3},
- 	{"belowright", 3},
- 	{"botright", 2},
- 	{"browse", 3},
- 	{"confirm", 4},
- 	{"hide", 3},
- 	{"keepalt", 5},
- 	{"keepjumps", 5},
- 	{"keepmarks", 3},
- 	{"leftabove", 5},
- 	{"lockmarks", 3},
- 	{"rightbelow", 6},
- 	{"sandbox", 3},
- 	{"silent", 3},
- 	{"tab", 3},
- 	{"topleft", 2},
- 	{"verbose", 4},
- 	{"vertical", 4},
-     };
  
      /* Check command modifiers. */
      for (i = 0; i < sizeof(cmdmods) / sizeof(struct cmdmod); ++i)
--- 3028,3033 ----
*** ../vim-7.1.161/src/ex_eval.c	Wed Aug  1 15:47:06 2007
--- src/ex_eval.c	Sat Nov 24 16:34:09 2007
***************
*** 2269,2277 ****
  has_loop_cmd(p)
      char_u	*p;
  {
!     p = skipwhite(p);
!     while (*p == ':')
! 	p = skipwhite(p + 1);
      if ((p[0] == 'w' && p[1] == 'h')
  	    || (p[0] == 'f' && p[1] == 'o' && p[2] == 'r'))
  	return TRUE;
--- 2269,2286 ----
  has_loop_cmd(p)
      char_u	*p;
  {
!     int		len;
! 
!     /* skip modifiers, white space and ':' */
!     for (;;)
!     {
! 	while (*p == ' ' || *p == '\t' || *p == ':')
! 	    ++p;
! 	len = modifier_len(p);
! 	if (len == 0)
! 	    break;
! 	p += len;
!     }
      if ((p[0] == 'w' && p[1] == 'h')
  	    || (p[0] == 'f' && p[1] == 'o' && p[2] == 'r'))
  	return TRUE;
*** ../vim-7.1.161/src/version.c	Sat Nov 24 21:27:33 2007
--- src/version.c	Sat Nov 24 21:48:38 2007
***************
*** 668,669 ****
--- 668,671 ----
  {   /* Add new patch number below this line */
+ /**/
+     162,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
144. You eagerly await the update of the "Cool Site of the Day."

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///