@@ -2930,13 +2930,19 @@ add_text_props_for_append(
29302930 {
29312931 if (round == 2 )
29322932 {
2933+ uint16_t pc ;
2934+
29332935 if (new_prop_count == 0 )
29342936 return ; // nothing to do
2935- new_len = * len + new_prop_count * sizeof (textprop_T );
2937+ new_len = * len + (int )PROP_COUNT_SIZE
2938+ + new_prop_count * (int )sizeof (textprop_T );
29362939 new_line = alloc (new_len );
29372940 if (new_line == NULL )
29382941 return ;
29392942 mch_memmove (new_line , * line , * len );
2943+ // Write prop_count header.
2944+ pc = (uint16_t )new_prop_count ;
2945+ mch_memmove (new_line + * len , & pc , PROP_COUNT_SIZE );
29402946 new_prop_count = 0 ;
29412947 }
29422948
@@ -2954,8 +2960,10 @@ add_text_props_for_append(
29542960 prop .tp_flags |= TP_FLAG_CONT_PREV ;
29552961 prop .tp_col = 1 ;
29562962 prop .tp_len = * len ; // not exactly the right length
2957- mch_memmove (new_line + * len + new_prop_count
2958- * sizeof (textprop_T ), & prop , sizeof (textprop_T ));
2963+ prop .u .tp_text_offset = 0 ;
2964+ mch_memmove (new_line + * len + (int )PROP_COUNT_SIZE
2965+ + new_prop_count * sizeof (textprop_T ),
2966+ & prop , sizeof (textprop_T ));
29592967 }
29602968 ++ new_prop_count ;
29612969 }
@@ -3772,34 +3780,48 @@ adjust_text_props_for_delete(
37723780 textlen = STRLEN (text ) + 1 ;
37733781 if ((long )textlen >= line_size )
37743782 {
3783+ // No properties on this line.
37753784 if (above )
37763785 internal_error ("no text property above deleted line" );
37773786 else
37783787 internal_error ("no text property below deleted line" );
37793788 return ;
37803789 }
3781- this_props_len = line_size - (int )textlen ;
3790+ if ((long )textlen + (long )PROP_COUNT_SIZE > line_size )
3791+ {
3792+ internal_error ("text property data too short" );
3793+ return ;
3794+ }
3795+
3796+ uint16_t pc ;
3797+
3798+ mch_memmove (& pc , text + textlen , PROP_COUNT_SIZE );
3799+ this_props_len = pc * (int )sizeof (textprop_T );
37823800 }
37833801
37843802 found = FALSE;
3785- for (done_this = 0 ; done_this < this_props_len ;
3786- done_this += sizeof (textprop_T ))
37873803 {
3788- int flag = above ? TP_FLAG_CONT_NEXT
3804+ char_u * props_start = text + textlen + PROP_COUNT_SIZE ;
3805+
3806+ for (done_this = 0 ; done_this < this_props_len ;
3807+ done_this += sizeof (textprop_T ))
3808+ {
3809+ int flag = above ? TP_FLAG_CONT_NEXT
37893810 : TP_FLAG_CONT_PREV ;
3790- textprop_T prop_this ;
3811+ textprop_T prop_this ;
37913812
3792- mch_memmove (& prop_this , text + textlen + done_this ,
3813+ mch_memmove (& prop_this , props_start + done_this ,
37933814 sizeof (textprop_T ));
3794- if ((prop_this .tp_flags & flag )
3795- && prop_del .tp_id == prop_this .tp_id
3796- && prop_del .tp_type == prop_this .tp_type )
3797- {
3798- found = TRUE;
3799- prop_this .tp_flags &= ~flag ;
3800- mch_memmove (text + textlen + done_this , & prop_this ,
3815+ if ((prop_this .tp_flags & flag )
3816+ && prop_del .tp_id == prop_this .tp_id
3817+ && prop_del .tp_type == prop_this .tp_type )
3818+ {
3819+ found = TRUE;
3820+ prop_this .tp_flags &= ~flag ;
3821+ mch_memmove (props_start + done_this , & prop_this ,
38013822 sizeof (textprop_T ));
3802- break ;
3823+ break ;
3824+ }
38033825 }
38043826 }
38053827 if (!found )
@@ -4003,13 +4025,23 @@ ml_delete_int(buf_T *buf, linenr_T lnum, int flags)
40034025#ifdef FEAT_PROP_POPUP
40044026 if (textprop_save != NULL )
40054027 {
4028+ // textprop_save is [prop_count][textprop_T...][vtext...].
4029+ // Skip prop_count header and pass only the textprop_T part.
4030+ uint16_t pc ;
4031+ char_u * props_data ;
4032+ int props_bytes ;
4033+
4034+ mch_memmove (& pc , textprop_save , PROP_COUNT_SIZE );
4035+ props_data = textprop_save + PROP_COUNT_SIZE ;
4036+ props_bytes = pc * (int )sizeof (textprop_T );
4037+
40064038 // Adjust text properties in the line above and below.
40074039 if (lnum > 1 )
4008- adjust_text_props_for_delete (buf , lnum - 1 , textprop_save ,
4009- ( int ) textprop_len , TRUE);
4040+ adjust_text_props_for_delete (buf , lnum - 1 ,
4041+ props_data , props_bytes , TRUE);
40104042 if (lnum <= buf -> b_ml .ml_line_count )
4011- adjust_text_props_for_delete (buf , lnum , textprop_save ,
4012- ( int ) textprop_len , FALSE);
4043+ adjust_text_props_for_delete (buf , lnum ,
4044+ props_data , props_bytes , FALSE);
40134045 }
40144046 vim_free (textprop_save );
40154047#endif
0 commit comments