Index: screen.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/screen.c,v
retrieving revision 1.109
diff -c -r1.109 screen.c
*** screen.c	2 Oct 2008 16:04:00 -0000	1.109
--- screen.c	19 Feb 2009 19:25:45 -0000
***************
*** 7364,7370 ****
--- 7364,7374 ----
  #endif
      static int	    entered = FALSE;		/* avoid recursiveness */
      static int	    done_outofmem_msg = FALSE;	/* did outofmem message */
+ #ifdef FEAT_AUTOCMD
+     int	    	    retry_count = 0;
  
+ retry:
+ #endif
      /*
       * Allocation of the screen buffers is done only when the size changes and
       * when Rows and Columns have been set and we have started doing full
***************
*** 7636,7643 ****
      --RedrawingDisabled;
  
  #ifdef FEAT_AUTOCMD
!     if (starting == 0)
  	apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf);
  #endif
  }
  
--- 7640,7658 ----
      --RedrawingDisabled;
  
  #ifdef FEAT_AUTOCMD
!     /* 
!      * Do not apply autocommands more than 3 times to avoid endless loop
!      * in case applying autocommands always changed Rows or Columns.
!      */
!     if (starting == 0 && ++retry_count <= 3)
!     {
  	apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf);
+ 	/*
+ 	 * In rare cases, autocommands may have altered Rows or Columns so
+ 	 * check if we need to allocate the screen again.
+ 	 */
+ 	goto retry;
+     }
  #endif
  }
  
