0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.0.0607: after :bwipe + :new bufref might still be valid

Problem:    When creating a bufref, then using :bwipe and :new it might get
            the same memory and bufref_valid() returns true.
Solution:   Add br_fnum to check the buffer number didn't change.
This commit is contained in:
Bram Moolenaar
2017-06-04 14:58:02 +02:00
parent 6e62da3e14
commit 45e5fd135d
6 changed files with 24 additions and 15 deletions

View File

@@ -372,18 +372,23 @@ open_buffer(
set_bufref(bufref_T *bufref, buf_T *buf)
{
bufref->br_buf = buf;
bufref->br_fnum = buf->b_fnum;
bufref->br_buf_free_count = buf_free_count;
}
/*
* Return TRUE if "bufref->br_buf" points to a valid buffer.
* Return TRUE if "bufref->br_buf" points to the same buffer as when
* set_bufref() was called and it is a valid buffer.
* Only goes through the buffer list if buf_free_count changed.
* Also checks if b_fnum is still the same, a :bwipe followed by :new might get
* the same allocated memory, but it's a different buffer.
*/
int
bufref_valid(bufref_T *bufref)
{
return bufref->br_buf_free_count == buf_free_count
? TRUE : buf_valid(bufref->br_buf);
? TRUE : buf_valid(bufref->br_buf)
&& bufref->br_fnum == bufref->br_buf->b_fnum;
}
/*
@@ -2261,14 +2266,14 @@ free_buf_options(
}
/*
* get alternate file n
* set linenr to lnum or altfpos.lnum if lnum == 0
* also set cursor column to altfpos.col if 'startofline' is not set.
* Get alternate file "n".
* Set linenr to "lnum" or altfpos.lnum if "lnum" == 0.
* Also set cursor column to altfpos.col if 'startofline' is not set.
* if (options & GETF_SETMARK) call setpcmark()
* if (options & GETF_ALT) we are jumping to an alternate file.
* if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping
*
* return FAIL for failure, OK for success
* Return FAIL for failure, OK for success.
*/
int
buflist_getfile(
@@ -2999,7 +3004,7 @@ buflist_findlnum(buf_T *buf)
#if defined(FEAT_LISTCMDS) || defined(PROTO)
/*
* List all know file names (for :files and :buffers command).
* List all known file names (for :files and :buffers command).
*/
void
buflist_list(exarg_T *eap)