comparison src/buffer.c @ 4139:2f7883063b19 v7.3.822

updated for version 7.3.822 Problem: Crash when accessing freed buffer. Solution: Get 'textwidth' in caller of enter_buffer(). (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Sun, 17 Feb 2013 15:45:37 +0100
parents 2eb4b9ed2d42
children 23ce9a61bdc2
comparison
equal deleted inserted replaced
4138:84cc49b2da4f 4139:2f7883063b19
79 int flags; /* extra flags for readfile() */ 79 int flags; /* extra flags for readfile() */
80 { 80 {
81 int retval = OK; 81 int retval = OK;
82 #ifdef FEAT_AUTOCMD 82 #ifdef FEAT_AUTOCMD
83 buf_T *old_curbuf; 83 buf_T *old_curbuf;
84 #endif
85 #ifdef FEAT_SYN_HL
86 long old_tw = curbuf->b_p_tw;
84 #endif 87 #endif
85 88
86 /* 89 /*
87 * The 'readonly' flag is only set when BF_NEVERLOADED is being reset. 90 * The 'readonly' flag is only set when BF_NEVERLOADED is being reset.
88 * When re-entering the same buffer, it should not change, because the 91 * When re-entering the same buffer, it should not change, because the
111 EMSG(_("E82: Cannot allocate any buffer, exiting...")); 114 EMSG(_("E82: Cannot allocate any buffer, exiting..."));
112 getout(2); 115 getout(2);
113 } 116 }
114 EMSG(_("E83: Cannot allocate buffer, using other one...")); 117 EMSG(_("E83: Cannot allocate buffer, using other one..."));
115 enter_buffer(curbuf); 118 enter_buffer(curbuf);
119 #ifdef FEAT_SYN_HL
120 if (old_tw != curbuf->b_p_tw)
121 check_colorcolumn(curwin);
122 #endif
116 return FAIL; 123 return FAIL;
117 } 124 }
118 125
119 #ifdef FEAT_AUTOCMD 126 #ifdef FEAT_AUTOCMD
120 /* The autocommands in readfile() may change the buffer, but only AFTER 127 /* The autocommands in readfile() may change the buffer, but only AFTER
784 buf_T *old_curbuf; 791 buf_T *old_curbuf;
785 { 792 {
786 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) 793 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
787 cleanup_T cs; 794 cleanup_T cs;
788 # endif 795 # endif
796 #ifdef FEAT_SYN_HL
797 long old_tw = curbuf->b_p_tw;
798 #endif
789 799
790 if (swap_exists_action == SEA_QUIT) 800 if (swap_exists_action == SEA_QUIT)
791 { 801 {
792 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) 802 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
793 /* Reset the error/interrupt/exception state here so that 803 /* Reset the error/interrupt/exception state here so that
802 swap_exists_did_quit = TRUE; 812 swap_exists_did_quit = TRUE;
803 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE); 813 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE);
804 if (!buf_valid(old_curbuf) || old_curbuf == curbuf) 814 if (!buf_valid(old_curbuf) || old_curbuf == curbuf)
805 old_curbuf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED); 815 old_curbuf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED);
806 if (old_curbuf != NULL) 816 if (old_curbuf != NULL)
817 {
807 enter_buffer(old_curbuf); 818 enter_buffer(old_curbuf);
819 #ifdef FEAT_SYN_HL
820 if (old_tw != curbuf->b_p_tw)
821 check_colorcolumn(curwin);
822 #endif
823 }
808 /* If "old_curbuf" is NULL we are in big trouble here... */ 824 /* If "old_curbuf" is NULL we are in big trouble here... */
809 825
810 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) 826 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
811 /* Restore the error/interrupt/exception state if not discarded by a 827 /* Restore the error/interrupt/exception state if not discarded by a
812 * new aborting error, interrupt, or uncaught exception. */ 828 * new aborting error, interrupt, or uncaught exception. */
1362 int action; 1378 int action;
1363 { 1379 {
1364 buf_T *prevbuf; 1380 buf_T *prevbuf;
1365 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL 1381 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
1366 || action == DOBUF_WIPE); 1382 || action == DOBUF_WIPE);
1383 #ifdef FEAT_SYN_HL
1384 long old_tw = curbuf->b_p_tw;
1385 #endif
1367 1386
1368 setpcmark(); 1387 setpcmark();
1369 if (!cmdmod.keepalt) 1388 if (!cmdmod.keepalt)
1370 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */ 1389 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */
1371 buflist_altfpos(curwin); /* remember curpos */ 1390 buflist_altfpos(curwin); /* remember curpos */
1428 # ifdef FEAT_WINDOWS 1447 # ifdef FEAT_WINDOWS
1429 ) || curwin->w_buffer == NULL 1448 ) || curwin->w_buffer == NULL
1430 # endif 1449 # endif
1431 ) 1450 )
1432 #endif 1451 #endif
1452 {
1433 enter_buffer(buf); 1453 enter_buffer(buf);
1454 #ifdef FEAT_SYN_HL
1455 if (old_tw != curbuf->b_p_tw)
1456 check_colorcolumn(curwin);
1457 #endif
1458 }
1434 } 1459 }
1435 1460
1436 /* 1461 /*
1437 * Enter a new current buffer. 1462 * Enter a new current buffer.
1438 * Old curbuf must have been abandoned already! 1463 * Old curbuf must have been abandoned already! This also means "curbuf" may
1464 * be pointing to freed memory.
1439 */ 1465 */
1440 void 1466 void
1441 enter_buffer(buf) 1467 enter_buffer(buf)
1442 buf_T *buf; 1468 buf_T *buf;
1443 { 1469 {
1444 #ifdef FEAT_SYN_HL
1445 long old_tw = curbuf->b_p_tw;
1446 #endif
1447
1448 /* Copy buffer and window local option values. Not for a help buffer. */ 1470 /* Copy buffer and window local option values. Not for a help buffer. */
1449 buf_copy_options(buf, BCO_ENTER | BCO_NOHELP); 1471 buf_copy_options(buf, BCO_ENTER | BCO_NOHELP);
1450 if (!buf->b_help) 1472 if (!buf->b_help)
1451 get_winopts(buf); 1473 get_winopts(buf);
1452 #ifdef FEAT_FOLDING 1474 #ifdef FEAT_FOLDING
1466 diff_buf_add(curbuf); 1488 diff_buf_add(curbuf);
1467 #endif 1489 #endif
1468 1490
1469 #ifdef FEAT_SYN_HL 1491 #ifdef FEAT_SYN_HL
1470 curwin->w_s = &(buf->b_s); 1492 curwin->w_s = &(buf->b_s);
1471 if (old_tw != buf->b_p_tw)
1472 check_colorcolumn(curwin);
1473 #endif 1493 #endif
1474 1494
1475 /* Cursor on first line by default. */ 1495 /* Cursor on first line by default. */
1476 curwin->w_cursor.lnum = 1; 1496 curwin->w_cursor.lnum = 1;
1477 curwin->w_cursor.col = 0; 1497 curwin->w_cursor.col = 0;