@@ -2871,16 +2871,18 @@ screen_multi_cursor(Screen *self, int queried_shape, int *params, unsigned num_p
28712871 write_escape_code_to_child (self , ESC_CSI , ">-1;1;2;3 q" );
28722872 } else if (queried_shape == -2 ) {
28732873 size_t sz = self -> extra_cursors .count * 32 + 64 ;
2874- RAII_ALLOC (char , buf , malloc (sz ));
2874+ RAII_ALLOC (char , buf , malloc (sz )); sz -= 4 ;
28752875 if (buf ) {
28762876 char * p = buf + snprintf (buf , sz , ">-2;" );
28772877 for (unsigned i = 0 ; i < self -> extra_cursors .count ; i ++ ) {
28782878 index_type cell = self -> extra_cursors .locations [i ].cell , shape = self -> extra_cursors .locations [i ].shape ;
28792879 index_type y = cell / self -> columns , x = cell - (y * self -> columns );
2880- p += snprintf (p , sz - (p - buf ), "%d:2:%u:%u;" , shape > 3 ? -1 : (int )shape , y + 1 , x + 1 );
2880+ int n = snprintf (p , sz - (p - buf ), "%d:2:%u:%u;" , shape > 3 ? -1 : (int )shape , y + 1 , x + 1 );
2881+ if (n < 0 || (unsigned )n > (sz - (p - buf ))) break ;
2882+ p += n ;
28812883 }
28822884 if (* (p - 1 ) == ';' ) p -- ;
2883- p += snprintf ( p , sz - ( p - buf ), " q" ) ; * p = 0 ;
2885+ * ( p ++ ) = ' ' ; * ( p ++ ) = 'q' ; * ( p ++ ) = 0 ;
28842886 write_escape_code_to_child (self , ESC_CSI , buf );
28852887 }
28862888 }
@@ -2950,7 +2952,7 @@ screen_multi_cursor(Screen *self, int queried_shape, int *params, unsigned num_p
29502952 for (unsigned i = 0 ; i + 3 < num_params ; i += 4 ) {
29512953 index_type top = params [i ]- 1 , left = params [i + 1 ]- 1 , bottom = params [i + 2 ]- 1 , right = params [i + 3 ]- 1 ;
29522954 bottom = MIN (bottom , self -> lines - 1 ); right = MIN (right , self -> columns - 1 );
2953- index_type xnum = right + 1 - left , ynum = bottom + 1 - top ;
2955+ size_t xnum = right + 1 - left , ynum = bottom + 1 - top ;
29542956 ensure_space_for (& self -> extra_cursors , locations , ExtraCursor ,
29552957 self -> extra_cursors .count + xnum * ynum , capacity , 20 * 80 , false);
29562958 for (index_type y = top ; y <= bottom ; y ++ ) {
0 commit comments