]> granicus.if.org Git - vim/commitdiff
patch 9.0.1225: reading past the end of a line when formatting text v9.0.1225
authorBram Moolenaar <Bram@vim.org>
Sat, 21 Jan 2023 13:09:19 +0000 (13:09 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 21 Jan 2023 13:09:19 +0000 (13:09 +0000)
Problem:    Reading past the end of a line when formatting text.
Solution:   Check for not going over the end of the line.

src/textformat.c
src/version.c

index 6a93890bd2c442a8732839a0c7e653dfe870a0c9..7ebbc8849a4594b8969932baf0b3ad035cb89fdb 100644 (file)
@@ -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;
index 29c788d2b4bdaf163d522f83f83e5f4112ea15f3..6a11b7fcb1bbb9d64987151868cfb69526ed8049 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1225,
 /**/
     1224,
 /**/