diff options
Diffstat (limited to 'src/nvim/indent.c')
-rw-r--r-- | src/nvim/indent.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 3cc64e0033..13534ac1a9 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -6,6 +6,7 @@ #include <stdbool.h> #include "nvim/ascii.h" +#include "nvim/assert.h" #include "nvim/indent.h" #include "nvim/eval.h" #include "nvim/charset.h" @@ -204,7 +205,12 @@ int set_indent(int size, int flags) // after the if (!curbuf->b_p_et) below. if (orig_char_len != -1) { assert(orig_char_len + size - ind_done + line_len >= 0); - newline = xmalloc((size_t)(orig_char_len + size - ind_done + line_len)); + size_t n; // = orig_char_len + size - ind_done + line_len + size_t n2; + STRICT_ADD(orig_char_len, size, &n, size_t); + STRICT_ADD(ind_done, line_len, &n2, size_t); + STRICT_SUB(n, n2, &n, size_t); + newline = xmalloc(n); todo = size - ind_done; // Set total length of indent in characters, which may have been @@ -226,7 +232,9 @@ int set_indent(int size, int flags) } else { todo = size; assert(ind_len + line_len >= 0); - newline = xmalloc((size_t)(ind_len + line_len)); + size_t newline_size; + STRICT_ADD(ind_len, line_len, &newline_size, size_t); + newline = xmalloc(newline_size); s = newline; } @@ -392,7 +400,9 @@ int copy_indent(int size, char_u *src) // and the rest of the line. line_len = (int)STRLEN(get_cursor_line_ptr()) + 1; assert(ind_len + line_len >= 0); - line = xmalloc((size_t)(ind_len + line_len)); + size_t line_size; + STRICT_ADD(ind_len, line_len, &line_size, size_t); + line = xmalloc(line_size); p = line; } } @@ -463,8 +473,8 @@ int get_breakindent_win(win_T *wp, char_u *line) static char_u *prev_line = NULL; // cached pointer to line. static varnumber_T prev_tick = 0; // Changedtick of cached value. int bri = 0; - /* window width minus window margin space, i.e. what rests for text */ - const int eff_wwidth = wp->w_width + // window width minus window margin space, i.e. what rests for text + const int eff_wwidth = wp->w_grid.Columns - ((wp->w_p_nu || wp->w_p_rnu) && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0); @@ -544,10 +554,8 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. char_u *inde_copy = vim_strsave(curbuf->b_p_inde); - if (inde_copy != NULL) { - indent = (int)eval_to_number(inde_copy); - xfree(inde_copy); - } + indent = (int)eval_to_number(inde_copy); + xfree(inde_copy); if (use_sandbox) { sandbox--; |