summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2023-01-21 13:09:19 +0000
committerBram Moolenaar <Bram@vim.org>2023-01-21 13:09:19 +0000
commit11977f917506d950b7e0cae558bd9189260b253b (patch)
treea2130b27f9c08040b4774d6e2265695b8501a5c8
parent47bba53bdb6d59057887149e2eeb2071803e547e (diff)
patch 9.0.1225: reading past the end of a line when formatting textv9.0.1225
Problem: Reading past the end of a line when formatting text. Solution: Check for not going over the end of the line.
-rw-r--r--src/textformat.c10
-rw-r--r--src/version.c2
2 files changed, 11 insertions, 1 deletions
diff --git a/src/textformat.c b/src/textformat.c
index 6a93890bd2..7ebbc8849a 100644
--- 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;
diff --git a/src/version.c b/src/version.c
index 29c788d2b4..6a11b7fcb1 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1225,
+/**/
1224,
/**/
1223,