mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
vim-patch:8.2.2820: session file may divide by zero
Problem: Session file may divide by zero.
Solution: Avoid writing difide by zero. (closes vim/vim#8162)
b6c2e9a010
Avoid typecasts if possible.
Use PRIdLINENR, PRId64, to format line numbers.
This commit is contained in:
parent
dd935e1473
commit
44a331c36b
@ -447,18 +447,25 @@ static int put_view(
|
||||
if (do_cursor) {
|
||||
// Restore the cursor line in the file and relatively in the
|
||||
// window. Don't use "G", it changes the jumplist.
|
||||
if (wp->w_height_inner <= 0) {
|
||||
if (fprintf(fd, "let s:l = %" PRIdLINENR "\n", wp->w_cursor.lnum) < 0) {
|
||||
return FAIL;
|
||||
}
|
||||
} else if (fprintf(fd,
|
||||
"let s:l = %" PRIdLINENR " - ((%" PRIdLINENR
|
||||
" * winheight(0) + %" PRId64 ") / %" PRId64 ")\n",
|
||||
wp->w_cursor.lnum,
|
||||
wp->w_cursor.lnum - wp->w_topline,
|
||||
(int64_t)(wp->w_height_inner / 2),
|
||||
(int64_t)wp->w_height_inner) < 0) {
|
||||
return FAIL;
|
||||
}
|
||||
if (fprintf(fd,
|
||||
"let s:l = %" PRId64 " - ((%" PRId64
|
||||
" * winheight(0) + %" PRId64 ") / %" PRId64 ")\n"
|
||||
"if s:l < 1 | let s:l = 1 | endif\n"
|
||||
"keepjumps exe s:l\n"
|
||||
"normal! zt\n"
|
||||
"keepjumps %" PRId64 "\n",
|
||||
(int64_t)wp->w_cursor.lnum,
|
||||
(int64_t)(wp->w_cursor.lnum - wp->w_topline),
|
||||
(int64_t)(wp->w_height_inner / 2),
|
||||
(int64_t)wp->w_height_inner,
|
||||
(int64_t)wp->w_cursor.lnum) < 0) {
|
||||
"keepjumps %" PRIdLINENR "\n",
|
||||
wp->w_cursor.lnum) < 0) {
|
||||
return FAIL;
|
||||
}
|
||||
// Restore the cursor column and left offset when not wrapping.
|
||||
|
@ -149,6 +149,21 @@ func Test_mksession_large_winheight()
|
||||
call delete('Xtest_mks_winheight.out')
|
||||
endfunc
|
||||
|
||||
func Test_mksession_zero_winheight()
|
||||
set winminheight=0
|
||||
edit SomeFile
|
||||
split
|
||||
wincmd _
|
||||
mksession! Xtest_mks_zero
|
||||
set winminheight&
|
||||
" let text = readfile('Xtest_mks_zero')->join()
|
||||
let text = join(readfile('Xtest_mks_zero'))
|
||||
"call delete('Xtest_mks_zero')
|
||||
close
|
||||
" check there is no devide by zero
|
||||
call assert_notmatch('/ 0[^0-9]', text)
|
||||
endfunc
|
||||
|
||||
func Test_mksession_rtp()
|
||||
if has('win32')
|
||||
" TODO: fix problem with backslashes
|
||||
|
Loading…
Reference in New Issue
Block a user