patch 9.1.1346: missing out-of-memory check in textformat.c Commit: https://github.com/vim/vim/commit/c25368ba14a7135b685ba3d6941f26bc630a2501 Author: John Marriott <basil...@internode.on.net> Date: Fri Apr 25 19:14:38 2025 +0200
patch 9.1.1346: missing out-of-memory check in textformat.c Problem: missing out-of-memory check in textformat.c Solution: add out-of-memory check, add small optimizations to internal_format() and same_leader() (John Marriott) closes: #17200 Signed-off-by: John Marriott <basil...@internode.on.net> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/textformat.c b/src/textformat.c index 018565f72..1af4b2f4d 100644 --- a/src/textformat.c +++ b/src/textformat.c @@ -369,7 +369,7 @@ internal_format( { // In MODE_VREPLACE state, we will backspace over the text to be // wrapped, so save a copy now to put on the next line. - saved_text = vim_strsave(ml_get_cursor()); + saved_text = vim_strnsave(ml_get_cursor(), ml_get_cursor_len()); curwin->w_cursor.col = orig_col; if (saved_text == NULL) break; // Can't do it, out of memory @@ -552,9 +552,7 @@ same_leader( char_u *leader2_flags) { int idx1 = 0, idx2 = 0; - char_u *p; char_u *line1; - char_u *line2; if (leader1_len == 0) return (leader2_len == 0); @@ -566,6 +564,8 @@ same_leader( // some text after it and the second line has the 'm' flag. if (leader1_flags != NULL) { + char_u *p; + for (p = leader1_flags; *p && *p != ':'; ++p) { if (*p == COM_FIRST) @@ -589,9 +589,11 @@ same_leader( // Get current line and next line, compare the leaders. // The first line has to be saved, only one line can be locked at a time. - line1 = vim_strsave(ml_get(lnum)); + line1 = vim_strnsave(ml_get(lnum), ml_get_len(lnum)); if (line1 != NULL) { + char_u *line2; + for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) ; line2 = ml_get(lnum + 1); @@ -665,11 +667,8 @@ auto_format( int prev_line) // may start in previous line { pos_T pos; - colnr_T len; char_u *old; - char_u *new, *pnew; int wasatend; - int cc; if (!has_format_option(FO_AUTO)) return; @@ -688,6 +687,8 @@ auto_format( wasatend = (pos.col == ml_get_curline_len()); if (*old != NUL && !trailblank && wasatend) { + int cc; + dec_cursor(); cc = gchar_cursor(); if (!WHITECHAR(cc) && curwin->w_cursor.col > 0 @@ -740,11 +741,13 @@ auto_format( // formatted. if (!wasatend && has_format_option(FO_WHITE_PAR)) { - new = ml_get_curline(); - len = ml_get_curline_len(); + char_u *new = ml_get_curline(); + colnr_T len = ml_get_curline_len(); if (curwin->w_cursor.col == len) { - pnew = vim_strnsave(new, len + 2); + char_u *pnew = vim_strnsave(new, len + 2); + if (pnew == NULL) + return; pnew[len] = ' '; pnew[len + 1] = NUL; ml_replace(curwin->w_cursor.lnum, pnew, FALSE); diff --git a/src/version.c b/src/version.c index 4f7996a99..c4db34af8 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1346, /**/ 1345, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1u8MsF-007RNR-Ac%40256bit.org.