diff options
Diffstat (limited to '')
-rw-r--r-- | src/drawline.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/drawline.c b/src/drawline.c index 81577be..e388bdb 100644 --- a/src/drawline.c +++ b/src/drawline.c @@ -296,10 +296,9 @@ get_sign_display_info( if (nrcol) { wlv->c_extra = NUL; - sprintf((char *)wlv->extra, "%-*c ", - number_width(wp), SIGN_BYTE); + wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), + "%-*c ", number_width(wp), SIGN_BYTE); wlv->p_extra = wlv->extra; - wlv->n_extra = (int)STRLEN(wlv->p_extra); } else wlv->c_extra = SIGN_BYTE; @@ -310,10 +309,9 @@ get_sign_display_info( if (nrcol) { wlv->c_extra = NUL; - sprintf((char *)wlv->extra, "%-*c ", number_width(wp), - MULTISIGN_BYTE); + wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), + "%-*c ", number_width(wp), MULTISIGN_BYTE); wlv->p_extra = wlv->extra; - wlv->n_extra = (int)STRLEN(wlv->p_extra); } else wlv->c_extra = MULTISIGN_BYTE; @@ -332,17 +330,18 @@ get_sign_display_info( if (nrcol) { int width = number_width(wp) - 2; - int n; - for (n = 0; n < width; n++) - wlv->extra[n] = ' '; - vim_snprintf((char *)wlv->extra + n, - sizeof(wlv->extra) - n, "%s ", wlv->p_extra); + vim_memset(wlv->extra, ' ', width); + wlv->n_extra = width; + wlv->n_extra += vim_snprintf((char *)wlv->extra + width, + sizeof(wlv->extra) - width, "%s ", wlv->p_extra); wlv->p_extra = wlv->extra; } + else + wlv->n_extra = (int)STRLEN(wlv->p_extra); + wlv->c_extra = NUL; wlv->c_final = NUL; - wlv->n_extra = (int)STRLEN(wlv->p_extra); } if (use_cursor_line_highlight(wp, wlv->lnum) @@ -417,7 +416,7 @@ handle_lnum_col( } } - sprintf((char *)wlv->extra, fmt, number_width(wp), num); + vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num); if (wp->w_skipcol > 0 && wlv->startrow == 0) for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' '; ++wlv->p_extra) @@ -621,25 +620,26 @@ textprop_size_after_trunc( { int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE)) ? wp->w_width - win_col_off(wp) : added; - int len = (int)STRLEN(text); int strsize = 0; - int n_used; + char_u *p; - // if the remaining size is to small and 'wrap' is set we wrap anyway and + // if the remaining size is too small and 'wrap' is set we wrap anyway and // use the next line if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap) space += wp->w_width; if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE)) space -= padding; - for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used)) + + for (p = text; *p != NUL; p += (*mb_ptr2len)(p)) { - int clen = ptr2cells(text + n_used); + int clen = ptr2cells(p); if (strsize + clen > space) break; strsize += clen; } - *n_used_ptr = n_used; + *n_used_ptr = (int)(p - text); + return strsize; } @@ -1801,13 +1801,13 @@ win_line( pos = wp->w_cursor; wp->w_cursor.lnum = lnum; wp->w_cursor.col = linecol; - len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); + len = spell_move_to(wp, FORWARD, SMT_ALL, TRUE, &spell_hlf); // spell_move_to() may call ml_get() and make "line" invalid line = ml_get_buf(wp->w_buffer, lnum, FALSE); ptr = line + linecol; - if (len == 0 || (int)wp->w_cursor.col > ptr - line) + if (len == 0 || (int)wp->w_cursor.col > linecol) { // no bad word found at line start, don't check until end of a // word @@ -2821,15 +2821,16 @@ win_line( // head byte at end of line mb_l = 1; transchar_nonprint(wp->w_buffer, wlv.extra, c); + wlv.n_extra = (int)STRLEN(wlv.extra) - 1; } else { // illegal tail byte mb_l = 2; STRCPY(wlv.extra, "XX"); + wlv.n_extra = 1; } wlv.p_extra = wlv.extra; - wlv.n_extra = (int)STRLEN(wlv.extra) - 1; wlv.c_extra = NUL; wlv.c_final = NUL; c = *wlv.p_extra++; @@ -3388,11 +3389,16 @@ win_line( c = *wlv.p_extra; p = alloc(wlv.n_extra + 1); - vim_memset(p, ' ', wlv.n_extra); - STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1); - p[wlv.n_extra] = NUL; - vim_free(wlv.p_extra_free); - wlv.p_extra_free = wlv.p_extra = p; + if (p == NULL) + wlv.n_extra = 0; + else + { + vim_memset(p, ' ', wlv.n_extra); + STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1); + p[wlv.n_extra] = NUL; + vim_free(wlv.p_extra_free); + wlv.p_extra_free = wlv.p_extra = p; + } } else #endif @@ -4251,7 +4257,7 @@ win_line( if (!wp->w_p_wrap && text_prop_follows && !text_prop_above) { // do not output more of the line, only the "below" prop - ptr += STRLEN(ptr); + ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum); # ifdef FEAT_LINEBREAK wlv.dont_use_showbreak = TRUE; # endif |