1
0
forked from aniani/vim

patch 8.1.0582: text properties are not enabled

Problem:    Text properties are not enabled.
Solution:   Fix sizeof argument and re-enable the text properties feature.
            Fix memory leak.
This commit is contained in:
Bram Moolenaar
2018-12-14 12:18:11 +01:00
parent ca79a5fc3b
commit fb95e212a2
3 changed files with 17 additions and 11 deletions

View File

@@ -505,7 +505,7 @@
* +textprop Text properties * +textprop Text properties
*/ */
#if defined(FEAT_EVAL) && defined(FEAT_SYN_HL) #if defined(FEAT_EVAL) && defined(FEAT_SYN_HL)
// # define FEAT_TEXT_PROP # define FEAT_TEXT_PROP
#endif #endif
/* /*

View File

@@ -151,7 +151,7 @@ f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
size_t textlen; size_t textlen;
char_u *props; char_u *props;
char_u *newprops; char_u *newprops;
static textprop_T tmp_prop; // static to get it aligned. textprop_T tmp_prop;
int i; int i;
lnum = get_tv_number(&argvars[0]); lnum = get_tv_number(&argvars[0]);
@@ -212,8 +212,9 @@ f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
// Fetch the line to get the ml_line_len field updated. // Fetch the line to get the ml_line_len field updated.
proplen = get_text_props(buf, lnum, &props, TRUE); proplen = get_text_props(buf, lnum, &props, TRUE);
textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
if (col >= (colnr_T)STRLEN(buf->b_ml.ml_line_ptr)) if (col >= (colnr_T)textlen - 1)
{ {
EMSGN(_(e_invalid_col), (long)col); EMSGN(_(e_invalid_col), (long)col);
return; return;
@@ -224,7 +225,6 @@ f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
if (newtext == NULL) if (newtext == NULL)
return; return;
// Copy the text, including terminating NUL. // Copy the text, including terminating NUL.
textlen = buf->b_ml.ml_line_len - proplen * sizeof(textprop_T);
mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen); mch_memmove(newtext, buf->b_ml.ml_line_ptr, textlen);
// Find the index where to insert the new property. // Find the index where to insert the new property.
@@ -232,8 +232,8 @@ f_prop_add(typval_T *argvars, typval_T *rettv UNUSED)
// text, we need to copy them as bytes before using it as a struct. // text, we need to copy them as bytes before using it as a struct.
for (i = 0; i < proplen; ++i) for (i = 0; i < proplen; ++i)
{ {
mch_memmove(&tmp_prop, props + i * sizeof(proptype_T), mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
sizeof(proptype_T)); sizeof(textprop_T));
if (tmp_prop.tp_col >= col) if (tmp_prop.tp_col >= col)
break; break;
} }
@@ -274,7 +274,7 @@ has_any_text_properties(buf_T *buf)
} }
/* /*
* Fetch the text properties for line "lnum" in buffer 'buf". * Fetch the text properties for line "lnum" in buffer "buf".
* Returns the number of text properties and, when non-zero, a pointer to the * Returns the number of text properties and, when non-zero, a pointer to the
* first one in "props" (note that it is not aligned, therefore the char_u * first one in "props" (note that it is not aligned, therefore the char_u
* pointer). * pointer).
@@ -617,11 +617,13 @@ prop_type_set(typval_T *argvars, int add)
{ {
*htp = (hashtab_T *)alloc(sizeof(hashtab_T)); *htp = (hashtab_T *)alloc(sizeof(hashtab_T));
if (*htp == NULL) if (*htp == NULL)
{
vim_free(prop);
return; return;
}
hash_init(*htp); hash_init(*htp);
} }
hash_add(buf == NULL ? global_proptypes : buf->b_proptypes, hash_add(*htp, PT2HIKEY(prop));
PT2HIKEY(prop));
} }
else else
{ {
@@ -640,7 +642,7 @@ prop_type_set(typval_T *argvars, int add)
char_u *highlight; char_u *highlight;
int hl_id = 0; int hl_id = 0;
highlight = get_dict_string(dict, (char_u *)"highlight", TRUE); highlight = get_dict_string(dict, (char_u *)"highlight", FALSE);
if (highlight != NULL && *highlight != NUL) if (highlight != NULL && *highlight != NUL)
hl_id = syn_name2id(highlight); hl_id = syn_name2id(highlight);
if (hl_id <= 0) if (hl_id <= 0)
@@ -721,12 +723,14 @@ f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED)
if (hi != NULL) if (hi != NULL)
{ {
hashtab_T *ht; hashtab_T *ht;
proptype_T *prop = HI2PT(hi);
if (buf == NULL) if (buf == NULL)
ht = global_proptypes; ht = global_proptypes;
else else
ht = buf->b_proptypes; ht = buf->b_proptypes;
hash_remove(ht, hi); hash_remove(ht, hi);
vim_free(prop);
} }
} }
@@ -846,7 +850,7 @@ clear_ht_prop_types(hashtab_T *ht)
#if defined(EXITFREE) || defined(PROTO) #if defined(EXITFREE) || defined(PROTO)
/* /*
* Free all property types for "buf". * Free all global property types.
*/ */
void void
clear_global_prop_types(void) clear_global_prop_types(void)

View File

@@ -799,6 +799,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
582,
/**/ /**/
581, 581,
/**/ /**/