summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0470
blob: d9b7e630512e6a7f572843e51ff0ede3a43c8cd9 (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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0470
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.0470
Problem:    Pointer ownership around fname_expand() is unclear.
Solution:   Allow b_ffname and b_sfname to point to the same allocated memory,
            only free one.  Update comments.
Files:	    src/buffer.c, src/structs.h, src/fileio.c, src/ex_cmds.c


*** ../vim-8.1.0469/src/buffer.c	2018-09-30 21:43:17.175693433 +0200
--- src/buffer.c	2018-10-11 19:00:11.004662173 +0200
***************
*** 663,670 ****
  	    workshop_file_closed_lineno((char *)buf->b_ffname,
  			(int)buf->b_last_cursor.lnum);
  #endif
! 	vim_free(buf->b_ffname);
! 	vim_free(buf->b_sfname);
  	if (buf->b_prev == NULL)
  	    firstbuf = buf->b_next;
  	else
--- 663,673 ----
  	    workshop_file_closed_lineno((char *)buf->b_ffname,
  			(int)buf->b_last_cursor.lnum);
  #endif
! 	if (buf->b_sfname != buf->b_ffname)
! 	    VIM_CLEAR(buf->b_sfname);
! 	else
! 	    buf->b_sfname = NULL;
! 	VIM_CLEAR(buf->b_ffname);
  	if (buf->b_prev == NULL)
  	    firstbuf = buf->b_next;
  	else
***************
*** 1877,1887 ****
   */
      buf_T *
  buflist_new(
!     char_u	*ffname,	/* full path of fname or relative */
!     char_u	*sfname,	/* short fname or NULL */
!     linenr_T	lnum,		/* preferred cursor line */
!     int		flags)		/* BLN_ defines */
  {
      buf_T	*buf;
  #ifdef UNIX
      stat_T	st;
--- 1880,1892 ----
   */
      buf_T *
  buflist_new(
!     char_u	*ffname_arg,	// full path of fname or relative
!     char_u	*sfname_arg,	// short fname or NULL
!     linenr_T	lnum,		// preferred cursor line
!     int		flags)		// BLN_ defines
  {
+     char_u	*ffname = ffname_arg;
+     char_u	*sfname = sfname_arg;
      buf_T	*buf;
  #ifdef UNIX
      stat_T	st;
***************
*** 1890,1896 ****
      if (top_file_num == 1)
  	hash_init(&buf_hashtab);
  
!     fname_expand(curbuf, &ffname, &sfname);	/* will allocate ffname */
  
      /*
       * If file name already exists in the list, update the entry.
--- 1895,1901 ----
      if (top_file_num == 1)
  	hash_init(&buf_hashtab);
  
!     fname_expand(curbuf, &ffname, &sfname);	// will allocate ffname
  
      /*
       * If file name already exists in the list, update the entry.
***************
*** 1997,2004 ****
      if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL))
  	    || buf->b_wininfo == NULL)
      {
  	VIM_CLEAR(buf->b_ffname);
- 	VIM_CLEAR(buf->b_sfname);
  	if (buf != curbuf)
  	    free_buffer(buf);
  	return NULL;
--- 2002,2012 ----
      if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL))
  	    || buf->b_wininfo == NULL)
      {
+ 	if (buf->b_sfname != buf->b_ffname)
+ 	    VIM_CLEAR(buf->b_sfname);
+ 	else
+ 	    buf->b_sfname = NULL;
  	VIM_CLEAR(buf->b_ffname);
  	if (buf != curbuf)
  	    free_buffer(buf);
  	return NULL;
***************
*** 3103,3109 ****
  }
  
  /*
!  * Set the file name for "buf"' to 'ffname', short file name to 'sfname'.
   * The file name with the full path is also remembered, for when :cd is used.
   * Returns FAIL for failure (file name already in use by other buffer)
   *	OK otherwise.
--- 3111,3118 ----
  }
  
  /*
!  * Set the file name for "buf"' to "ffname_arg", short file name to
!  * "sfname_arg".
   * The file name with the full path is also remembered, for when :cd is used.
   * Returns FAIL for failure (file name already in use by other buffer)
   *	OK otherwise.
***************
*** 3111,3120 ****
      int
  setfname(
      buf_T	*buf,
!     char_u	*ffname,
!     char_u	*sfname,
      int		message)	/* give message when buffer already exists */
  {
      buf_T	*obuf = NULL;
  #ifdef UNIX
      stat_T	st;
--- 3120,3131 ----
      int
  setfname(
      buf_T	*buf,
!     char_u	*ffname_arg,
!     char_u	*sfname_arg,
      int		message)	/* give message when buffer already exists */
  {
+     char_u	*ffname = ffname_arg;
+     char_u	*sfname = sfname_arg;
      buf_T	*obuf = NULL;
  #ifdef UNIX
      stat_T	st;
***************
*** 3123,3130 ****
      if (ffname == NULL || *ffname == NUL)
      {
  	/* Removing the name. */
  	VIM_CLEAR(buf->b_ffname);
- 	VIM_CLEAR(buf->b_sfname);
  #ifdef UNIX
  	st.st_dev = (dev_T)-1;
  #endif
--- 3134,3144 ----
      if (ffname == NULL || *ffname == NUL)
      {
  	/* Removing the name. */
+ 	if (buf->b_sfname != buf->b_ffname)
+ 	    VIM_CLEAR(buf->b_sfname);
+ 	else
+ 	    buf->b_sfname = NULL;
  	VIM_CLEAR(buf->b_ffname);
  #ifdef UNIX
  	st.st_dev = (dev_T)-1;
  #endif
***************
*** 3175,3182 ****
  # endif
  	    fname_case(sfname, 0);    /* set correct case for short file name */
  #endif
  	vim_free(buf->b_ffname);
- 	vim_free(buf->b_sfname);
  	buf->b_ffname = ffname;
  	buf->b_sfname = sfname;
      }
--- 3189,3197 ----
  # endif
  	    fname_case(sfname, 0);    /* set correct case for short file name */
  #endif
+ 	if (buf->b_sfname != buf->b_ffname)
+ 	    vim_free(buf->b_sfname);
  	vim_free(buf->b_ffname);
  	buf->b_ffname = ffname;
  	buf->b_sfname = sfname;
      }
***************
*** 3210,3216 ****
      buf = buflist_findnr(fnum);
      if (buf != NULL)
      {
! 	vim_free(buf->b_sfname);
  	vim_free(buf->b_ffname);
  	buf->b_ffname = vim_strsave(name);
  	buf->b_sfname = NULL;
--- 3225,3232 ----
      buf = buflist_findnr(fnum);
      if (buf != NULL)
      {
! 	if (buf->b_sfname != buf->b_ffname)
! 	    vim_free(buf->b_sfname);
  	vim_free(buf->b_ffname);
  	buf->b_ffname = vim_strsave(name);
  	buf->b_sfname = NULL;
***************
*** 4820,4827 ****
  }
  
  /*
!  * Make "ffname" a full file name, set "sfname" to "ffname" if not NULL.
!  * "ffname" becomes a pointer to allocated memory (or NULL).
   */
      void
  fname_expand(
--- 4836,4847 ----
  }
  
  /*
!  * Make "*ffname" a full file name, set "*sfname" to "*ffname" if not NULL.
!  * "*ffname" becomes a pointer to allocated memory (or NULL).
!  * When resolving a link both "*sfname" and "*ffname" will point to the same
!  * allocated memory.
!  * The "*ffname" and "*sfname" pointer values on call will not be freed.
!  * Note that the resulting "*ffname" pointer should be considered not allocaed.
   */
      void
  fname_expand(
***************
*** 4829,4846 ****
      char_u	**ffname,
      char_u	**sfname)
  {
!     if (*ffname == NULL)	/* if no file name given, nothing to do */
  	return;
!     if (*sfname == NULL)	/* if no short file name given, use ffname */
  	*sfname = *ffname;
!     *ffname = fix_fname(*ffname);   /* expand to full path */
  
  #ifdef FEAT_SHORTCUT
      if (!buf->b_p_bin)
      {
  	char_u  *rfname;
  
! 	/* If the file name is a shortcut file, use the file it links to. */
  	rfname = mch_resolve_shortcut(*ffname);
  	if (rfname != NULL)
  	{
--- 4849,4866 ----
      char_u	**ffname,
      char_u	**sfname)
  {
!     if (*ffname == NULL)	    // no file name given, nothing to do
  	return;
!     if (*sfname == NULL)	    // no short file name given, use ffname
  	*sfname = *ffname;
!     *ffname = fix_fname(*ffname);   // expand to full path
  
  #ifdef FEAT_SHORTCUT
      if (!buf->b_p_bin)
      {
  	char_u  *rfname;
  
! 	// If the file name is a shortcut file, use the file it links to.
  	rfname = mch_resolve_shortcut(*ffname);
  	if (rfname != NULL)
  	{
*** ../vim-8.1.0469/src/structs.h	2018-10-02 18:25:41.420867587 +0200
--- src/structs.h	2018-10-11 17:45:36.197140877 +0200
***************
*** 1972,1980 ****
       * b_fname is the same as b_sfname, unless ":cd" has been done,
       *		then it is the same as b_ffname (NULL for no name).
       */
!     char_u	*b_ffname;	/* full path file name */
!     char_u	*b_sfname;	/* short file name */
!     char_u	*b_fname;	/* current file name */
  
  #ifdef UNIX
      int		b_dev_valid;	/* TRUE when b_dev has a valid number */
--- 1972,1982 ----
       * b_fname is the same as b_sfname, unless ":cd" has been done,
       *		then it is the same as b_ffname (NULL for no name).
       */
!     char_u	*b_ffname;	// full path file name, allocated
!     char_u	*b_sfname;	// short file name, allocated, may be equal to
! 				// b_ffname
!     char_u	*b_fname;	// current file name, points to b_ffname or
! 				// b_sfname
  
  #ifdef UNIX
      int		b_dev_valid;	/* TRUE when b_dev has a valid number */
*** ../vim-8.1.0469/src/fileio.c	2018-09-30 21:43:17.187693348 +0200
--- src/fileio.c	2018-10-11 18:50:41.084975167 +0200
***************
*** 6187,6193 ****
  		|| buf->b_sfname == NULL
  		|| mch_isFullName(buf->b_sfname)))
      {
! 	VIM_CLEAR(buf->b_sfname);
  	p = shorten_fname(buf->b_ffname, dirname);
  	if (p != NULL)
  	{
--- 6187,6194 ----
  		|| buf->b_sfname == NULL
  		|| mch_isFullName(buf->b_sfname)))
      {
! 	if (buf->b_sfname != buf->b_ffname)
! 	    VIM_CLEAR(buf->b_sfname);
  	p = shorten_fname(buf->b_ffname, dirname);
  	if (p != NULL)
  	{
*** ../vim-8.1.0469/src/ex_cmds.c	2018-10-09 21:49:30.447622031 +0200
--- src/ex_cmds.c	2018-10-11 19:01:12.524192986 +0200
***************
*** 3648,3655 ****
  }
  
  /*
!  * Try to abandon current file and edit a new or existing file.
!  * "fnum" is the number of the file, if zero use ffname/sfname.
   * "lnum" is the line number for the cursor in the new file (if non-zero).
   *
   * Return:
--- 3648,3655 ----
  }
  
  /*
!  * Try to abandon the current file and edit a new or existing file.
!  * "fnum" is the number of the file, if zero use "ffname_arg"/"sfname_arg".
   * "lnum" is the line number for the cursor in the new file (if non-zero).
   *
   * Return:
***************
*** 3661,3672 ****
      int
  getfile(
      int		fnum,
!     char_u	*ffname,
!     char_u	*sfname,
      int		setpm,
      linenr_T	lnum,
      int		forceit)
  {
      int		other;
      int		retval;
      char_u	*free_me = NULL;
--- 3661,3674 ----
      int
  getfile(
      int		fnum,
!     char_u	*ffname_arg,
!     char_u	*sfname_arg,
      int		setpm,
      linenr_T	lnum,
      int		forceit)
  {
+     char_u	*ffname = ffname_arg;
+     char_u	*sfname = sfname_arg;
      int		other;
      int		retval;
      char_u	*free_me = NULL;
*** ../vim-8.1.0469/src/version.c	2018-10-11 17:39:09.173107491 +0200
--- src/version.c	2018-10-11 18:57:27.585905972 +0200
***************
*** 794,795 ****
--- 794,797 ----
  {   /* Add new patch number below this line */
+ /**/
+     470,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
189. You put your e-mail address in the upper left-hand corner of envelopes.

 /// 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    ///