summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0013
blob: fedac815d3026500db1b9ba6070be1951339a255 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0013
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 8.1.0013
Problem:    Using freed memory when changing terminal cursor color.
Solution:   Make a copy of the color. (Dominique Pelle, closes #2938,
            closes #2941)
Files:	    src/terminal.c


*** ../vim-8.1.0012/src/terminal.c	2018-05-17 13:17:10.000000000 +0200
--- src/terminal.c	2018-05-21 14:46:25.723564355 +0200
***************
*** 171,178 ****
  
  /* Store the last set and the desired cursor properties, so that we only update
   * them when needed.  Doing it unnecessary may result in flicker. */
! static char_u	*last_set_cursor_color = (char_u *)"";
! static char_u	*desired_cursor_color = (char_u *)"";
  static int	last_set_cursor_shape = -1;
  static int	desired_cursor_shape = -1;
  static int	last_set_cursor_blink = -1;
--- 171,178 ----
  
  /* Store the last set and the desired cursor properties, so that we only update
   * them when needed.  Doing it unnecessary may result in flicker. */
! static char_u	*last_set_cursor_color = NULL;
! static char_u	*desired_cursor_color = NULL;
  static int	last_set_cursor_shape = -1;
  static int	desired_cursor_shape = -1;
  static int	last_set_cursor_blink = -1;
***************
*** 183,188 ****
--- 183,210 ----
   * 1. Generic code for all systems.
   */
  
+     static void
+ cursor_color_copy(char_u** to_color, char_u* from_color)
+ {
+     vim_free(*to_color);
+     *to_color = (from_color == NULL) ? NULL : vim_strsave(from_color);
+ }
+ 
+ 	static int
+ cursor_color_equal(char_u *lhs_color, char_u *rhs_color)
+ {
+     if (lhs_color != NULL && rhs_color != NULL)
+ 	return STRCMP(lhs_color, rhs_color) == 0;
+     return lhs_color == NULL && rhs_color == NULL;
+ }
+ 
+ 	static char_u *
+ cursor_color_get(char_u *color)
+ {
+     return (color == NULL) ? (char_u *)"" : color;
+ }
+ 
+ 
  /*
   * Parse 'termwinsize' and set "rows" and "cols" for the terminal size in the
   * current window.
***************
*** 823,830 ****
      if (term->tl_out_fd != NULL)
  	fclose(term->tl_out_fd);
  #endif
-     if (desired_cursor_color == term->tl_cursor_color)
- 	desired_cursor_color = (char_u *)"";
      vim_free(term->tl_cursor_color);
      vim_free(term);
      buf->b_term = NULL;
--- 845,850 ----
***************
*** 1954,1967 ****
      static void
  may_output_cursor_props(void)
  {
!     if (STRCMP(last_set_cursor_color, desired_cursor_color) != 0
  	    || last_set_cursor_shape != desired_cursor_shape
  	    || last_set_cursor_blink != desired_cursor_blink)
      {
! 	last_set_cursor_color = desired_cursor_color;
  	last_set_cursor_shape = desired_cursor_shape;
  	last_set_cursor_blink = desired_cursor_blink;
! 	term_cursor_color(desired_cursor_color);
  	if (desired_cursor_shape == -1 || desired_cursor_blink == -1)
  	    /* this will restore the initial cursor style, if possible */
  	    ui_cursor_shape_forced(TRUE);
--- 1974,1987 ----
      static void
  may_output_cursor_props(void)
  {
!     if (!cursor_color_equal(last_set_cursor_color, desired_cursor_color)
  	    || last_set_cursor_shape != desired_cursor_shape
  	    || last_set_cursor_blink != desired_cursor_blink)
      {
! 	cursor_color_copy(&last_set_cursor_color, desired_cursor_color);
  	last_set_cursor_shape = desired_cursor_shape;
  	last_set_cursor_blink = desired_cursor_blink;
! 	term_cursor_color(cursor_color_get(desired_cursor_color));
  	if (desired_cursor_shape == -1 || desired_cursor_blink == -1)
  	    /* this will restore the initial cursor style, if possible */
  	    ui_cursor_shape_forced(TRUE);
***************
*** 1984,1993 ****
  #endif
      if (in_terminal_loop == term)
      {
! 	if (term->tl_cursor_color != NULL)
! 	    desired_cursor_color = term->tl_cursor_color;
! 	else
! 	    desired_cursor_color = (char_u *)"";
  	desired_cursor_shape = term->tl_cursor_shape;
  	desired_cursor_blink = term->tl_cursor_blink;
  	may_output_cursor_props();
--- 2004,2010 ----
  #endif
      if (in_terminal_loop == term)
      {
! 	cursor_color_copy(&desired_cursor_color, term->tl_cursor_color);
  	desired_cursor_shape = term->tl_cursor_shape;
  	desired_cursor_blink = term->tl_cursor_blink;
  	may_output_cursor_props();
***************
*** 2004,2010 ****
      if (gui.in_use)
  	return;
  #endif
!     desired_cursor_color = (char_u *)"";
      desired_cursor_shape = -1;
      desired_cursor_blink = -1;
      may_output_cursor_props();
--- 2021,2027 ----
      if (gui.in_use)
  	return;
  #endif
!     cursor_color_copy(&desired_cursor_color, NULL);
      desired_cursor_shape = -1;
      desired_cursor_blink = -1;
      may_output_cursor_props();
***************
*** 2624,2636 ****
  	    break;
  
  	case VTERM_PROP_CURSORCOLOR:
! 	    if (desired_cursor_color == term->tl_cursor_color)
! 		desired_cursor_color = (char_u *)"";
! 	    vim_free(term->tl_cursor_color);
! 	    if (*value->string == NUL)
! 		term->tl_cursor_color = NULL;
! 	    else
! 		term->tl_cursor_color = vim_strsave((char_u *)value->string);
  	    may_set_cursor_props(term);
  	    break;
  
--- 2641,2647 ----
  	    break;
  
  	case VTERM_PROP_CURSORCOLOR:
! 	    cursor_color_copy(&term->tl_cursor_color, (char_u*)value->string);
  	    may_set_cursor_props(term);
  	    break;
  
***************
*** 4711,4718 ****
  	dict_add_nr_str(d, "blink", blink_state_is_inverted()
  		       ? !term->tl_cursor_blink : term->tl_cursor_blink, NULL);
  	dict_add_nr_str(d, "shape", term->tl_cursor_shape, NULL);
! 	dict_add_nr_str(d, "color", 0L, term->tl_cursor_color == NULL
! 				       ? (char_u *)"" : term->tl_cursor_color);
  	list_append_dict(l, d);
      }
  }
--- 4722,4728 ----
  	dict_add_nr_str(d, "blink", blink_state_is_inverted()
  		       ? !term->tl_cursor_blink : term->tl_cursor_blink, NULL);
  	dict_add_nr_str(d, "shape", term->tl_cursor_shape, NULL);
! 	dict_add_nr_str(d, "color", 0L, cursor_color_get(term->tl_cursor_color));
  	list_append_dict(l, d);
      }
  }
*** ../vim-8.1.0012/src/version.c	2018-05-21 13:39:36.051906757 +0200
--- src/version.c	2018-05-21 14:47:20.927181563 +0200
***************
*** 763,764 ****
--- 763,766 ----
  {   /* Add new patch number below this line */
+ /**/
+     13,
  /**/

-- 
Friends?  I have lots of friends!  In fact, I have all episodes ever made.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///