comparison src/textprop.c @ 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 273649cad196
children 00aa76a735e7
comparison
equal deleted inserted replaced
15372:a9d7228471c1 15373:44dd3ce11201
977 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T), 977 mch_memmove(&tmp_prop, props + ri * sizeof(textprop_T),
978 sizeof(textprop_T)); 978 sizeof(textprop_T));
979 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type); 979 pt = text_prop_type_by_id(curbuf, tmp_prop.tp_type);
980 980
981 if (bytes_added > 0 981 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))
983 : (tmp_prop.tp_col > col + 1)) 985 : (tmp_prop.tp_col > col + 1))
984 { 986 {
985 tmp_prop.tp_col += bytes_added; 987 tmp_prop.tp_col += bytes_added;
986 dirty = TRUE; 988 dirty = TRUE;
987 } 989 }
988 else if (tmp_prop.tp_len > 0 990 else if (tmp_prop.tp_len > 0
989 && tmp_prop.tp_col + tmp_prop.tp_len > col 991 && 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))
991 ? 0 : 1)) 993 ? 0 : 1))
992 { 994 {
993 tmp_prop.tp_len += bytes_added; 995 tmp_prop.tp_len += bytes_added;
994 dirty = TRUE; 996 dirty = TRUE;
995 if (tmp_prop.tp_len <= 0) 997 if (tmp_prop.tp_len <= 0)
999 sizeof(textprop_T)); 1001 sizeof(textprop_T));
1000 ++wi; 1002 ++wi;
1001 } 1003 }
1002 if (dirty) 1004 if (dirty)
1003 { 1005 {
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);
1004 curbuf->b_ml.ml_flags |= ML_LINE_DIRTY; 1011 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;
1006 } 1013 }
1007 } 1014 }
1008 1015
1009 /* 1016 /*
1010 * Adjust text properties for a line that was split in two. 1017 * Adjust text properties for a line that was split in two.