Skip to content

Commit

Permalink
patch 9.0.1225: reading past the end of a line when formatting text
Browse files Browse the repository at this point in the history
Problem:    Reading past the end of a line when formatting text.
Solution:   Check for not going over the end of the line.
  • Loading branch information
brammool committed Jan 21, 2023
1 parent 47bba53 commit 11977f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/textformat.c
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1225,
/**/
1224,
/**/
Expand Down

0 comments on commit 11977f9

Please sign in to comment.