To: vim_dev@googlegroups.com Subject: Patch 8.2.2820 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2820 Problem: Session file may divide by zero. Solution: Avoid writing difide by zero. (closes #8162) Files: src/session.c, src/testdir/test_mksession.vim *** ../vim-8.2.2819/src/session.c 2021-04-17 18:38:49.888758511 +0200 --- src/session.c 2021-04-30 21:33:14.719804062 +0200 *************** *** 456,466 **** // 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)", (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 || 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 --- 456,474 ---- // Restore the cursor line in the file and relatively in the // window. Don't use "G", it changes the jumplist. ! 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) ! 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 *** ../vim-8.2.2819/src/testdir/test_mksession.vim 2021-04-17 21:04:22.054657370 +0200 --- src/testdir/test_mksession.vim 2021-04-30 21:28:17.024624728 +0200 *************** *** 179,184 **** --- 179,198 ---- 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 *** ../vim-8.2.2819/src/version.c 2021-04-30 19:43:06.618062735 +0200 --- src/version.c 2021-04-30 21:36:21.151289640 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2820, /**/ -- hundred-and-one symptoms of being an internet addict: 202. You're amazed to find out Spam is a food. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///