changeset 15373:44dd3ce11201 v8.1.0694

patch 8.1.0694: when using text props may free memory that is not allocated commit https://github.com/vim/vim/commit/4614f53e0f853b513963d1a639398348a571ecf1 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 6 12:54:55 2019 +0100 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)
author Bram Moolenaar <Bram@vim.org>
date Sun, 06 Jan 2019 13:00:05 +0100
parents a9d7228471c1
children 13a34f8e996b
files src/textprop.c src/version.c
diffstat 2 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/textprop.c
+++ b/src/textprop.c
@@ -979,7 +979,9 @@ adjust_prop_columns(
 	pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
 
 	if (bytes_added > 0
-		? (tmp_prop.tp_col >= col + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL) ? 2 : 1))
+		? (tmp_prop.tp_col >= col
+		       + (pt != NULL && (pt->pt_flags & PT_FLAG_INS_START_INCL)
+								      ? 2 : 1))
 		: (tmp_prop.tp_col > col + 1))
 	{
 	    tmp_prop.tp_col += bytes_added;
@@ -987,7 +989,7 @@ adjust_prop_columns(
 	}
 	else if (tmp_prop.tp_len > 0
 		&& tmp_prop.tp_col + tmp_prop.tp_len > col
-			+ ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
+		       + ((pt != NULL && (pt->pt_flags & PT_FLAG_INS_END_INCL))
 								      ? 0 : 1))
 	{
 	    tmp_prop.tp_len += bytes_added;
@@ -1001,8 +1003,13 @@ adjust_prop_columns(
     }
     if (dirty)
     {
+	colnr_T newlen = (int)textlen + wi * (colnr_T)sizeof(textprop_T);
+
+	if ((curbuf->b_ml.ml_flags & ML_LINE_DIRTY) == 0)
+	    curbuf->b_ml.ml_line_ptr =
+				 vim_memsave(curbuf->b_ml.ml_line_ptr, newlen);
 	curbuf->b_ml.ml_flags |= ML_LINE_DIRTY;
-	curbuf->b_ml.ml_line_len = (int)textlen + wi * sizeof(textprop_T);
+	curbuf->b_ml.ml_line_len = newlen;
     }
 }
 
--- a/src/version.c
+++ b/src/version.c
@@ -800,6 +800,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    694,
+/**/
     693,
 /**/
     692,