diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-10 21:18:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 21:18:12 +0800 |
commit | 9b1112cf48238260b170b8763b18a02a58159c2a (patch) | |
tree | a4a1c50014b7e1f4d373aa5648054b4cfb879baa /src/nvim/drawline.c | |
parent | 870ca1de52b240926b88f01afa697cd9b119bdac (diff) | |
download | rneovim-9b1112cf48238260b170b8763b18a02a58159c2a.tar.gz rneovim-9b1112cf48238260b170b8763b18a02a58159c2a.tar.bz2 rneovim-9b1112cf48238260b170b8763b18a02a58159c2a.zip |
fix(statuscolumn): fix crashes and clang/PVS warnings (#21725)
Diffstat (limited to 'src/nvim/drawline.c')
-rw-r--r-- | src/nvim/drawline.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 23ef7400b7..b1cdfe209b 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -450,14 +450,13 @@ static void get_statuscol_str(win_T *wp, linenr_T lnum, int row, int startrow, i stcp->textp = stcp->text; stcp->hlrecp = stcp->hlrec; stcp->cur_attr = stcp->num_attr; - stcp->text_len = strlen(stcp->text); + stcp->text_end = stcp->text + strlen(stcp->text); int fill = stcp->width - width; if (fill > 0) { // Fill up with ' ' - memset(&stcp->text[stcp->text_len], ' ', (size_t)fill); - stcp->text_len += (size_t)fill; - stcp->text[stcp->text_len] = NUL; + memset(stcp->text_end, ' ', (size_t)fill); + *(stcp->text_end += fill) = NUL; } } @@ -476,10 +475,9 @@ static void get_statuscol_display_info(LineDrawState *draw_state, int *char_attr *draw_state = WL_STC; *char_attr = stcp->cur_attr; *pp_extra = stcp->textp; - *n_extrap = stcp->hlrecp->start ? (int)(stcp->hlrecp->start - stcp->textp) - : (int)strlen(*pp_extra); + *n_extrap = (int)((stcp->hlrecp->start ? stcp->hlrecp->start : stcp->text_end) - stcp->textp); // Prepare for next highlight section if not yet at the end - if (stcp->textp + *n_extrap < stcp->text + stcp->text_len) { + if (stcp->textp + *n_extrap < stcp->text_end) { int hl = stcp->hlrecp->userhl; stcp->textp = stcp->hlrecp->start; stcp->cur_attr = hl < 0 ? syn_id2attr(-stcp->hlrecp->userhl) @@ -488,7 +486,7 @@ static void get_statuscol_display_info(LineDrawState *draw_state, int *char_attr *draw_state = WL_STC - 1; } // Skip over empty highlight sections - } while (*n_extrap == 0 && stcp->textp < stcp->text + stcp->text_len); + } while (*n_extrap == 0 && stcp->textp < stcp->text_end); } /// Return true if CursorLineNr highlight is to be used for the number column. @@ -1328,7 +1326,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, draw_state = WL_STC; // Draw the 'statuscolumn' if option is set. if (statuscol.draw) { - if (statuscol.text_len == 0) { + if (statuscol.textp == NULL) { get_statuscol_str(wp, lnum, row, startrow, filler_lines, cul_attr, sign_num_attr, sattrs, foldinfo, extra, &statuscol); if (wp->w_redr_statuscol) { @@ -2823,7 +2821,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool nochange, if (statuscol.draw) { if (row == startrow + 1 || row == startrow + filler_lines) { // Re-evaluate 'statuscolumn' for the first wrapped row and non filler line - statuscol.text_len = 0; + statuscol.textp = NULL; } else { // Otherwise just reset the text/hlrec pointers statuscol.textp = statuscol.text; statuscol.hlrecp = statuscol.hlrec; |