summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-30 21:37:51 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-30 21:37:51 +0200
commitb6c2e9a010ebd7db586081957e634903d4972fa1 (patch)
tree0060fb0ded71919735a9058173ef5aa5523a4845 /src
parent4934ed34c3e2090d1963c89c629cd3ce81d3ecd1 (diff)
downloadvim-git-b6c2e9a010ebd7db586081957e634903d4972fa1.tar.gz
patch 8.2.2820: session file may divide by zerov8.2.2820
Problem: Session file may divide by zero. Solution: Avoid writing difide by zero. (closes #8162)
Diffstat (limited to 'src')
-rw-r--r--src/session.c14
-rw-r--r--src/testdir/test_mksession.vim14
-rw-r--r--src/version.c2
3 files changed, 27 insertions, 3 deletions
diff --git a/src/session.c b/src/session.c
index 6d1ccb57e..8edf0dade 100644
--- a/src/session.c
+++ b/src/session.c
@@ -456,11 +456,19 @@ put_view(
// Restore the cursor line in the file and relatively in the
// window. Don't use "G", it changes the jumplist.
- if (fprintf(fd, "let s:l = %ld - ((%ld * winheight(0) + %ld) / %ld)",
+ if (wp->w_height <= 0)
+ {
+ if (fprintf(fd, "let s:l = %ld", (long)wp->w_cursor.lnum) < 0)
+ return FAIL;
+ }
+ else if (fprintf(fd,
+ "let s:l = %ld - ((%ld * winheight(0) + %ld) / %ld)",
(long)wp->w_cursor.lnum,
(long)(wp->w_cursor.lnum - wp->w_topline),
- (long)wp->w_height / 2, (long)wp->w_height) < 0
- || put_eol(fd) == FAIL
+ (long)wp->w_height / 2, (long)wp->w_height) < 0)
+ return FAIL;
+
+ if (put_eol(fd) == FAIL
|| put_line(fd, "if s:l < 1 | let s:l = 1 | endif") == FAIL
|| put_line(fd, "keepjumps exe s:l") == FAIL
|| put_line(fd, "normal! zt") == FAIL
diff --git a/src/testdir/test_mksession.vim b/src/testdir/test_mksession.vim
index 045aa2de0..e876f987c 100644
--- a/src/testdir/test_mksession.vim
+++ b/src/testdir/test_mksession.vim
@@ -179,6 +179,20 @@ 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()
+ "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()
" TODO: fix problem with backslashes on Win32
CheckNotMSWindows
diff --git a/src/version.c b/src/version.c
index b1ba0a119..ed632f7ba 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2820,
+/**/
2819,
/**/
2818,