comparison src/buffer.c @ 15557:c0560da7873e v8.1.0786

patch 8.1.0786: ml_get error when updating the status line commit https://github.com/vim/vim/commit/10772307c4e5299ed45470f92779f089a00d841e Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 20 18:25:54 2019 +0100 patch 8.1.0786: ml_get error when updating the status line Problem: ml_get error when updating the status line and a terminal had its scrollback cleared. (Chris Patuzzo) Solution: Check the cursor position when drawing the status line. (closes #3830)
author Bram Moolenaar <Bram@vim.org>
date Sun, 20 Jan 2019 18:30:06 +0100
parents d89c5b339c2a
children 1ec942f1b648
comparison
equal deleted inserted replaced
15556:83498c37ab4b 15557:c0560da7873e
3867 int fillchar, 3867 int fillchar,
3868 int maxwidth, 3868 int maxwidth,
3869 struct stl_hlrec *hltab, /* return: HL attributes (can be NULL) */ 3869 struct stl_hlrec *hltab, /* return: HL attributes (can be NULL) */
3870 struct stl_hlrec *tabtab) /* return: tab page nrs (can be NULL) */ 3870 struct stl_hlrec *tabtab) /* return: tab page nrs (can be NULL) */
3871 { 3871 {
3872 linenr_T lnum;
3873 size_t len;
3872 char_u *p; 3874 char_u *p;
3873 char_u *s; 3875 char_u *s;
3874 char_u *t; 3876 char_u *t;
3875 int byteval; 3877 int byteval;
3876 #ifdef FEAT_EVAL 3878 #ifdef FEAT_EVAL
3941 /* Can't handle a multi-byte fill character yet. */ 3943 /* Can't handle a multi-byte fill character yet. */
3942 else if (mb_char2len(fillchar) > 1) 3944 else if (mb_char2len(fillchar) > 1)
3943 fillchar = '-'; 3945 fillchar = '-';
3944 #endif 3946 #endif
3945 3947
3946 /* Get line & check if empty (cursorpos will show "0-1"). Note that 3948 // The cursor in windows other than the current one isn't always
3947 * p will become invalid when getting another buffer line. */ 3949 // up-to-date, esp. because of autocommands and timers.
3948 p = ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE); 3950 lnum = wp->w_cursor.lnum;
3951 if (lnum > wp->w_buffer->b_ml.ml_line_count)
3952 {
3953 lnum = wp->w_buffer->b_ml.ml_line_count;
3954 wp->w_cursor.lnum = lnum;
3955 }
3956
3957 // Get line & check if empty (cursorpos will show "0-1"). Note that
3958 // p will become invalid when getting another buffer line.
3959 p = ml_get_buf(wp->w_buffer, lnum, FALSE);
3949 empty_line = (*p == NUL); 3960 empty_line = (*p == NUL);
3950 3961
3951 /* Get the byte value now, in case we need it below. This is more 3962 // Get the byte value now, in case we need it below. This is more efficient
3952 * efficient than making a copy of the line. */ 3963 // than making a copy of the line.
3953 if (wp->w_cursor.col > (colnr_T)STRLEN(p)) 3964 len = STRLEN(p);
3965 if (wp->w_cursor.col > (colnr_T)len)
3966 {
3967 // Line may have changed since checking the cursor column, or the lnum
3968 // was adjusted above.
3969 wp->w_cursor.col = (colnr_T)len;
3970 #ifdef FEAT_VIRTUALEDIT
3971 wp->w_cursor.coladd = 0;
3972 #endif
3954 byteval = 0; 3973 byteval = 0;
3974 }
3955 else 3975 else
3956 #ifdef FEAT_MBYTE 3976 #ifdef FEAT_MBYTE
3957 byteval = (*mb_ptr2char)(p + wp->w_cursor.col); 3977 byteval = (*mb_ptr2char)(p + wp->w_cursor.col);
3958 #else 3978 #else
3959 byteval = p[wp->w_cursor.col]; 3979 byteval = p[wp->w_cursor.col];