Mercurial > vim
changeset 31786:4eb7db656c4a v9.0.1225
patch 9.0.1225: reading past the end of a line when formatting text
Commit: https://github.com/vim/vim/commit/11977f917506d950b7e0cae558bd9189260b253b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 21 13:09:19 2023 +0000
patch 9.0.1225: reading past the end of a line when formatting text
Problem: Reading past the end of a line when formatting text.
Solution: Check for not going over the end of the line.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 21 Jan 2023 17:00:39 +0100 |
parents | 2f3957acccad |
children | fb4192bcb42a |
files | src/textformat.c src/version.c |
diffstat | 2 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/textformat.c +++ b/src/textformat.c @@ -540,6 +540,9 @@ same_leader( if (leader1_len == 0) return (leader2_len == 0); + char_u *lnum_line = NULL; + int line_len = 0; + // If first leader has 'f' flag, the lines can be joined only if the // second line does not have a leader. // If first leader has 'e' flag, the lines can never be joined. @@ -555,7 +558,12 @@ same_leader( return FALSE; if (*p == COM_START) { - if (*(ml_get(lnum) + leader1_len) == NUL) + if (lnum_line == NULL) + { + lnum_line = ml_get(lnum); + line_len = (int)STRLEN(lnum_line); + } + if (line_len <= leader1_len) return FALSE; if (leader2_flags == NULL || leader2_len == 0) return FALSE;