Skip to content

Commit 4614f53

Browse files
committed
patch 8.1.0694: when using text props may free memory that is not allocated
Problem: When using text props may free memory that is not allocated. (Andy Massimino) Solution: Allocate the line when adjusting text props. (closes #3766)
1 parent f780b8a commit 4614f53

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/textprop.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,17 @@ adjust_prop_columns(
979979
pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
980980

981981
if (bytes_added > 0
982-
? (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1))
982+
? (tmp_prop.tp_col >= col
983+
+ (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)
984+
? 2 : 1))
983985
: (tmp_prop.tp_col > col + 1))
984986
{
985987
tmp_prop.tp_col += bytes_added;
986988
dirty = TRUE;
987989
}
988990
else if (tmp_prop.tp_len > 0
989991
&& tmp_prop.tp_col + tmp_prop.tp_len > col
990-
+ ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
992+
+ ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
991993
? 0 : 1))
992994
{
993995
tmp_prop.tp_len += bytes_added;
@@ -1001,8 +1003,13 @@ adjust_prop_columns(
10011003
}
10021004
if (dirty)
10031005
{
1006+
colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T);
1007+
1008+
if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0)
1009+
curbuf->b_ml.ml_line_ptr =
1010+
vim_memsave(curbuf->b_ml.ml_line_ptr, newlen);
10041011
curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
1005-
curbuf->b_ml.ml_line_len = (int)textlen + wi * sizeof(textprop_T);
1012+
curbuf->b_ml.ml_line_len = newlen;
10061013
}
10071014
}
10081015

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ static char *(features[]) =
799799

800800
static int included_patches[] =
801801
{ /* Add new patch number below this line */
802+
/**/
803+
694,
802804
/**/
803805
693,
804806
/**/

0 commit comments

Comments
 (0)