mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
fix #1027: :wundo segfault in new, non-empty buffer
This commit is contained in:
@@ -1009,7 +1009,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
int fd;
|
int fd;
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int perm;
|
int perm;
|
||||||
int write_ok = FALSE;
|
bool write_ok = false;
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
file_name = u_get_undo_file_name(buf->b_ffname, FALSE);
|
file_name = u_get_undo_file_name(buf->b_ffname, FALSE);
|
||||||
@@ -1116,7 +1116,8 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
*/
|
*/
|
||||||
FileInfo file_info_old;
|
FileInfo file_info_old;
|
||||||
FileInfo file_info_new;
|
FileInfo file_info_new;
|
||||||
if (os_fileinfo((char *)buf->b_ffname, &file_info_old)
|
if (buf->b_ffname != NULL
|
||||||
|
&& os_fileinfo((char *)buf->b_ffname, &file_info_old)
|
||||||
&& os_fileinfo((char *)file_name, &file_info_new)
|
&& os_fileinfo((char *)file_name, &file_info_new)
|
||||||
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid
|
&& file_info_old.stat.st_gid != file_info_new.stat.st_gid
|
||||||
&& os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) {
|
&& os_fchown(fd, -1, file_info_old.stat.st_gid) != 0) {
|
||||||
@@ -1177,7 +1178,7 @@ void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (put_bytes(fp, (long_u)UF_HEADER_END_MAGIC, 2) == OK)
|
if (put_bytes(fp, (long_u)UF_HEADER_END_MAGIC, 2) == OK)
|
||||||
write_ok = TRUE;
|
write_ok = true;
|
||||||
#ifdef U_DEBUG
|
#ifdef U_DEBUG
|
||||||
if (headers_written != buf->b_u_numhead) {
|
if (headers_written != buf->b_u_numhead) {
|
||||||
EMSGN("Written %" PRId64 " headers, ...", headers_written);
|
EMSGN("Written %" PRId64 " headers, ...", headers_written);
|
||||||
|
20
test/functional/ex_cmds/wundo_spec.lua
Normal file
20
test/functional/ex_cmds/wundo_spec.lua
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
-- Specs for
|
||||||
|
-- :wundo
|
||||||
|
|
||||||
|
local helpers = require('test.functional.helpers')
|
||||||
|
local execute, eq, clear, eval, feed =
|
||||||
|
helpers.execute, helpers.eq, helpers.clear, helpers.eval, helpers.feed
|
||||||
|
|
||||||
|
|
||||||
|
describe(':wundo', function()
|
||||||
|
before_each(clear)
|
||||||
|
|
||||||
|
it('safely fails on new, non-empty buffer', function()
|
||||||
|
feed('iabc<esc>')
|
||||||
|
execute('wundo foo') -- This should not segfault. #1027
|
||||||
|
--TODO: check messages for error message
|
||||||
|
|
||||||
|
os.remove(eval('getcwd()') .. '/foo') --cleanup
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
Reference in New Issue
Block a user