Re: Commit: patch 9.1.0409: too many strlen() calls in the regexp engine

2024-05-11 Fir de Conversatie John Marriott


On 12-May-2024 08:54, Tony Mechelynck wrote:

On Sun, May 12, 2024 at 12:15 AM Christian Brabandt  wrote:

patch 9.1.0409: too many strlen() calls in the regexp engine

Commit: 
https://github.com/vim/vim/commit/82792db6315f7c7b0e299cdde1566f2932a463f8
Author: John Marriott 
Date:   Sun May 12 00:07:17 2024 +0200

 patch 9.1.0409: too many strlen() calls in the regexp engine

 Problem:  too many strlen() calls in the regexp engine
 Solution: refactor code to retrieve strlen differently, make use
   of bsearch() for getting the character class
   (John Marriott)

 closes: #14648

 Signed-off-by: John Marriott 
 Signed-off-by: Christian Brabandt 




Hi Tony,

Please try the fix in PR#14754 or the attached patch.

Cheers
John

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/377c4060-08ba-466b-a759-737cabc15ddb%40internode.on.net.
--- ../../../vim/git/vim/src/regexp.c   2024-05-12 13:12:31.495260800 +1000
+++ ./regexp.c  2024-05-12 13:03:01.987293700 +1000
@@ -642,7 +642,7 @@
{
if (dirc == '?' && newp != NULL && p[1] == '?')
{
-   size_t  startplen;
+   size_t  startplen = 0;
 
// change "\?" to "?", make a copy first.
if (*newp == NULL)


Re: Commit: patch 9.1.0409: too many strlen() calls in the regexp engine

2024-05-11 Fir de Conversatie Tony Mechelynck
On Sun, May 12, 2024 at 12:15 AM Christian Brabandt  wrote:
>
> patch 9.1.0409: too many strlen() calls in the regexp engine
>
> Commit: 
> https://github.com/vim/vim/commit/82792db6315f7c7b0e299cdde1566f2932a463f8
> Author: John Marriott 
> Date:   Sun May 12 00:07:17 2024 +0200
>
> patch 9.1.0409: too many strlen() calls in the regexp engine
>
> Problem:  too many strlen() calls in the regexp engine
> Solution: refactor code to retrieve strlen differently, make use
>   of bsearch() for getting the character class
>   (John Marriott)
>
> closes: #14648
>
> Signed-off-by: John Marriott 
> Signed-off-by: Christian Brabandt 
>
[...]

Warning in gcc 13.2.1 (openSUSE) in all builds from Huge to Tiny in
regexp.c line 645:

regexp.c: In function ‘skip_regexp_ex’:
regexp.c:645:25: warning: ‘startplen’ may be used uninitialized
[-Wmaybe-uninitialized]
  645 | size_t  startplen;
  | ^

An executable is produced.

Best regards,
Tony.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAJkCKXtvrXPafgQKqDYWDm10gPFetnGyGHnLX%2B0gE6PLZyFBAA%40mail.gmail.com.


Commit: patch 9.1.0409: too many strlen() calls in the regexp engine

2024-05-11 Fir de Conversatie Christian Brabandt
patch 9.1.0409: too many strlen() calls in the regexp engine

Commit: 
https://github.com/vim/vim/commit/82792db6315f7c7b0e299cdde1566f2932a463f8
Author: John Marriott 
Date:   Sun May 12 00:07:17 2024 +0200

patch 9.1.0409: too many strlen() calls in the regexp engine

Problem:  too many strlen() calls in the regexp engine
Solution: refactor code to retrieve strlen differently, make use
  of bsearch() for getting the character class
  (John Marriott)

closes: #14648

Signed-off-by: John Marriott 
Signed-off-by: Christian Brabandt 

diff --git a/src/regexp.c b/src/regexp.c
index 4373ae0cf..c80f29af5 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -161,6 +161,7 @@ re_multi_type(int c)
 }
 
 static char_u  *reg_prev_sub = NULL;
+static size_t  reg_prev_sublen = 0;
 
 /*
  * REGEXP_INRANGE contains all characters which are always special in a []
@@ -197,6 +198,30 @@ backslash_trans(int c)
 return c;
 }
 
+enum
+{
+CLASS_ALNUM = 0,
+CLASS_ALPHA,
+CLASS_BLANK,
+CLASS_CNTRL,
+CLASS_DIGIT,
+CLASS_GRAPH,
+CLASS_LOWER,
+CLASS_PRINT,
+CLASS_PUNCT,
+CLASS_SPACE,
+CLASS_UPPER,
+CLASS_XDIGIT,
+CLASS_TAB,
+CLASS_RETURN,
+CLASS_BACKSPACE,
+CLASS_ESCAPE,
+CLASS_IDENT,
+CLASS_KEYWORD,
+CLASS_FNAME,
+CLASS_NONE = 99
+};
+
 /*
  * Check for a character class name "[:name:]".  "pp" points to the '['.
  * Returns one of the CLASS_ items. CLASS_NONE means that no item was
@@ -205,58 +230,56 @@ backslash_trans(int c)
 static int
 get_char_class(char_u **pp)
 {
-static const char *(class_names[]) =
+// must be sorted by the 'value' field because it is used by bsearch()!
+static keyvalue_T char_class_tab[] =
 {
-   "alnum:]",
-#define CLASS_ALNUM 0
-   "alpha:]",
-#define CLASS_ALPHA 1
-   "blank:]",
-#define CLASS_BLANK 2
-   "cntrl:]",
-#define CLASS_CNTRL 3
-   "digit:]",
-#define CLASS_DIGIT 4
-   "graph:]",
-#define CLASS_GRAPH 5
-   "lower:]",
-#define CLASS_LOWER 6
-   "print:]",
-#define CLASS_PRINT 7
-   "punct:]",
-#define CLASS_PUNCT 8
-   "space:]",
-#define CLASS_SPACE 9
-   "upper:]",
-#define CLASS_UPPER 10
-   "xdigit:]",
-#define CLASS_XDIGIT 11
-   "tab:]",
-#define CLASS_TAB 12
-   "return:]",
-#define CLASS_RETURN 13
-   "backspace:]",
-#define CLASS_BACKSPACE 14
-   "escape:]",
-#define CLASS_ESCAPE 15
-   "ident:]",
-#define CLASS_IDENT 16
-   "keyword:]",
-#define CLASS_KEYWORD 17
-   "fname:]",
-#define CLASS_FNAME 18
+   KEYVALUE_ENTRY(CLASS_ALNUM, "alnum:]"),
+   KEYVALUE_ENTRY(CLASS_ALPHA, "alpha:]"),
+   KEYVALUE_ENTRY(CLASS_BACKSPACE, "backspace:]"),
+   KEYVALUE_ENTRY(CLASS_BLANK, "blank:]"),
+   KEYVALUE_ENTRY(CLASS_CNTRL, "cntrl:]"),
+   KEYVALUE_ENTRY(CLASS_DIGIT, "digit:]"),
+   KEYVALUE_ENTRY(CLASS_ESCAPE, "escape:]"),
+   KEYVALUE_ENTRY(CLASS_FNAME, "fname:]"),
+   KEYVALUE_ENTRY(CLASS_GRAPH, "graph:]"),
+   KEYVALUE_ENTRY(CLASS_IDENT, "ident:]"),
+   KEYVALUE_ENTRY(CLASS_KEYWORD, "keyword:]"),
+   KEYVALUE_ENTRY(CLASS_LOWER, "lower:]"),
+   KEYVALUE_ENTRY(CLASS_PRINT, "print:]"),
+   KEYVALUE_ENTRY(CLASS_PUNCT, "punct:]"),
+   KEYVALUE_ENTRY(CLASS_RETURN, "return:]"),
+   KEYVALUE_ENTRY(CLASS_SPACE, "space:]"),
+   KEYVALUE_ENTRY(CLASS_TAB, "tab:]"),
+   KEYVALUE_ENTRY(CLASS_UPPER, "upper:]"),
+   KEYVALUE_ENTRY(CLASS_XDIGIT, "xdigit:]")
 };
-#define CLASS_NONE 99
-int i;
 
-if ((*pp)[1] == ':')
+// check that the value of "pp" has a chance of matching
+if ((*pp)[1] == ':' && ASCII_ISLOWER((*pp)[2])
+   && ASCII_ISLOWER((*pp)[3]) && ASCII_ISLOWER((*pp)[4]))
 {
-   for (i = 0; i < (int)ARRAY_LENGTH(class_names); ++i)
-   if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0)
-   {
-   *pp += STRLEN(class_names[i]) + 2;
-   return i;
-   }
+   keyvalue_T target;
+   keyvalue_T *entry;
+   // this function can be called repeatedly with the same value for "pp"
+   // so we cache the last found entry.
+   static keyvalue_T *last_entry = NULL;
+
+   target.key = 0;
+   target.value = (char *)*pp + 2;
+   target.length = 0;  // not used, see 
cmp_keyvalue_value_n()
+
+   if (last_entry != NULL && cmp_keyvalue_value_n(, last_entry) == 
0)
+   entry = last_entry;
+   else
+   entry = (keyvalue_T *)bsearch(, _class_tab,
+   ARRAY_LENGTH(char_class_tab),
+   sizeof(char_class_tab[0]), 
cmp_keyvalue_value_n);
+   if (entry != NULL)
+   {
+   last_entry = entry;
+   *pp += entry->length + 2;
+   return entry->key;
+   }
 }
 return CLASS_NONE;
 }
@@ -619,17 +642,20 @@ skip_regexp_ex(

Commit: ftplugin(python): E16 fix, async keyword support for define (#14751)

2024-05-11 Fir de Conversatie Christian Brabandt
ftplugin(python): E16 fix, async keyword support for define (#14751)

Commit: 
https://github.com/vim/vim/commit/86f6e2c2eed7df2bf5c60cc74d08d7a8d3c75f45
Author: Tom Picton 
Date:   Sat May 11 14:26:06 2024 -0400

ftplugin(python): E16 fix, async keyword support for define 
(https://github.com/vim/vim/issues/14751)

This change includes the following changes:
- Fix "E16: Invalid range" when using a count with jump to start/end of 
class/method
- Update define with optional async keyword
- Update maintainer email

Signed-off-by: Tom Picton 
Signed-off-by: Christian Brabandt 

diff --git a/runtime/ftplugin/python.vim b/runtime/ftplugin/python.vim
index 79acaa6f0..3a7190201 100644
--- a/runtime/ftplugin/python.vim
+++ b/runtime/ftplugin/python.vim
@@ -1,10 +1,9 @@
 " Vim filetype plugin file
 " Language:python
-" Maintainer:  Tom Picton 
+" Maintainer:  Tom Picton 
 " Previous Maintainer: James Sully 
 " Previous Maintainer: Johannes Zellner 
-" Last Change: Mon, 5 October 2020
-"  2024 Jan 14 by Vim Project (browsefilter)
+" Last Change: 2024/05/11
 " https://github.com/tpict/vim-ftplugin-python
 
 if exists("b:did_ftplugin") | finish | endif
@@ -15,7 +14,7 @@ set cpo
 setlocal cinkeys-=0#
 setlocal indentkeys-=0#
 setlocal include=^\s*\(from\\|import\)
-setlocal define=^\s*\(def\\|class\)
+setlocal define=^\s*\([async ]\?def\\|class\)
 
 " For imports with leading .., append / and replace additional .s with ../
 let b:grandparent_match = '^\(.\.\)\(\.*\)'
@@ -57,14 +56,14 @@ let b:next_end=' \S
*(%$\|^(\s*
*)*(class\|def\|async def)\|^\S)'
 let b:prev_end=' \S
*(^(\s*
*)*(class\|def\|async def)\|^\S)'
 
 if !exists('g:no_plugin_maps') && !exists('g:no_python_maps')
-execute "nnoremap   ]] :call Python_jump('n', '". 
b:next_toplevel."', 'W', v:count1)"
-execute "nnoremap   [[ :call Python_jump('n', '". 
b:prev_toplevel."', 'Wb', v:count1)"
-execute "nnoremap   ][ :call Python_jump('n', '". 
b:next_endtoplevel."', 'W', v:count1, 0)"
-execute "nnoremap   [] :call Python_jump('n', '". 
b:prev_endtoplevel."', 'Wb', v:count1, 0)"
-execute "nnoremap   ]m :call Python_jump('n', '". 
b:next."', 'W', v:count1)"
-execute "nnoremap   [m :call Python_jump('n', '". 
b:prev."', 'Wb', v:count1)"
-execute "nnoremap   ]M :call Python_jump('n', '". 
b:next_end."', 'W', v:count1, 0)"
-execute "nnoremap   [M :call Python_jump('n', '". 
b:prev_end."', 'Wb', v:count1, 0)"
+execute "nnoremap   ]] :call Python_jump('n', 
'". b:next_toplevel."', 'W', v:count1)"
+execute "nnoremap   [[ :call Python_jump('n', 
'". b:prev_toplevel."', 'Wb', v:count1)"
+execute "nnoremap   ][ :call Python_jump('n', 
'". b:next_endtoplevel."', 'W', v:count1, 0)"
+execute "nnoremap   [] :call Python_jump('n', 
'". b:prev_endtoplevel."', 'Wb', v:count1, 0)"
+execute "nnoremap   ]m :call Python_jump('n', 
'". b:next."', 'W', v:count1)"
+execute "nnoremap   [m :call Python_jump('n', 
'". b:prev."', 'Wb', v:count1)"
+execute "nnoremap   ]M :call Python_jump('n', 
'". b:next_end."', 'W', v:count1, 0)"
+execute "nnoremap   [M :call Python_jump('n', 
'". b:prev_end."', 'Wb', v:count1, 0)"
 
 execute "onoremap   ]] :call Python_jump('o', '". 
b:next_toplevel."', 'W', v:count1)"
 execute "onoremap   [[ :call Python_jump('o', '". 
b:prev_toplevel."', 'Wb', v:count1)"

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1s5rU0-00Cynj-1u%40256bit.org.


Commit: patch 9.1.0408: configure fails on Fedora when including perl

2024-05-11 Fir de Conversatie Christian Brabandt
patch 9.1.0408: configure fails on Fedora when including perl

Commit: 
https://github.com/vim/vim/commit/9c0ff47098ac20a8c93e8f91c0c8c72f9add3ce8
Author: Christian Brabandt 
Date:   Sat May 11 20:18:21 2024 +0200

patch 9.1.0408: configure fails on Fedora when including perl

Problem:  configure fails on Fedora when including perl
  (chesheer-smile)
Solution: Filter out -spec= from $LIBS and $LDFLAGS to avoid
  linking relocation errors for unrelated autoconf tests.

closes: #14526

Signed-off-by: Christian Brabandt 

diff --git a/src/auto/configure b/src/auto/configure
index 0e0cf8efe..8433133c6 100755
--- a/src/auto/configure
+++ b/src/auto/configure
@@ -6502,11 +6502,13 @@ printf "%s
" "$vi_cv_perl_xsubpp" >&6; }
-e 's/-flto\(=auto\)\? //' \
-e 's/-W[^ ]*//g' \
-e 's/-D_FORTIFY_SOURCE=.//g'`
-perllibs=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed -e 
'ldopts' | \
+  perllibs=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed -e 
'ldopts' | \
sed -e '/Warning/d' -e '/Note (probably harmless)/d' \
+   -e 's/-specs=[^ ]*//g' \
-e 's/-bE:perl.exp//' -e 's/-lc //'`
-  perlldflags=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed \
-   -e 'ccdlflags' | sed -e 's/-bE:perl.exp//'`
+perlldflags=`cd $srcdir; $vi_cv_path_perl 
-MExtUtils::Embed \
+   -e 'ccdlflags' | sed -e 's/-bE:perl.exp//' \
+   -e 's/-specs=[^ ]*//g' `
 
   { printf "%s
" "$as_me:${as_lineno-$LINENO}: checking if compile and link flags for Perl are 
sane" >&5
 printf %s "checking if compile and link flags for Perl are sane... " >&6; }
diff --git a/src/configure.ac b/src/configure.ac
index f6e54b30b..e092f686a 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -1173,13 +1173,17 @@ if test "$enable_perlinterp" = "yes" -o 
"$enable_perlinterp" = "dynamic"; then
-e 's/-W[[^ ]]*//g' \
-e 's/-D_FORTIFY_SOURCE=.//g'`
   dnl Remove "-lc", it breaks on FreeBSD when using "-pthread".
+  dnl Remove -specs=, the hardened flags cause relocation errors
   perllibs=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed -e 'ldopts' | \
sed -e '/Warning/d' -e '/Note (probably harmless)/d' \
+   -e 's/-specs=[[^ ]*]//g' \
-e 's/-bE:perl.exp//' -e 's/-lc //'`
   dnl Don't add perl lib to $LIBS: if it's not in LD_LIBRARY_PATH
   dnl a test in configure may fail because of that.
+  dnl Remove -specs=, the hardened flags cause relocation errors
   perlldflags=`cd $srcdir; $vi_cv_path_perl -MExtUtils::Embed \
-   -e 'ccdlflags' | sed -e 's/-bE:perl.exp//'`
+   -e 'ccdlflags' | sed -e 's/-bE:perl.exp//' \
+   -e 's/-specs=[[^ ]*]//g' `
 
   dnl check that compiling a simple program still works with the flags
   dnl added for Perl.
diff --git a/src/version.c b/src/version.c
index 828b3c78b..430e79698 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+408,
 /**/
 407,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1s5rTy-00Cymt-2z%40256bit.org.


Commit: patch 9.1.0407: Stuck with long line and half-page scrolling

2024-05-11 Fir de Conversatie Christian Brabandt
patch 9.1.0407: Stuck with long line and half-page scrolling

Commit: 
https://github.com/vim/vim/commit/58448e09be497a8abb595ae309b6edfbc8e0e05a
Author: Luuk van Baal 
Date:   Sat May 11 11:27:52 2024 +0200

patch 9.1.0407: Stuck with long line and half-page scrolling

Problem:  No scrolling happens with half-page scrolling with line
  filling entire window when 'smoothscroll' is disabled.
  (Mathias Rav, after v9.1.0285)
Solution: Adjust amount to move cursor by so that it is moved the same
  number of lines as was scrolled, even when scrolling different
  number of lines than requested with 'nosmoothscroll'.

fixes: #14743
closes: #14746

Signed-off-by: Luuk van Baal 
Signed-off-by: Christian Brabandt 

diff --git a/src/move.c b/src/move.c
index 797184812..3e589caae 100644
--- a/src/move.c
+++ b/src/move.c
@@ -3158,9 +3158,10 @@ static int get_scroll_overlap(int dir)
 
 /*
  * Scroll "count" lines with 'smoothscroll' in direction "dir". Return TRUE
- * when scrolling happened.
+ * when scrolling happened. Adjust "curscount" for scrolling different amount 
of
+ * lines when 'smoothscroll' is disabled.
  */
-static int scroll_with_sms(int dir, long count)
+static int scroll_with_sms(int dir, long count, long *curscount)
 {
 intprev_sms = curwin->w_p_sms;
 colnr_Tprev_skipcol = curwin->w_skipcol;
@@ -3183,7 +3184,10 @@ static int scroll_with_sms(int dir, long count)
fixdir = dir * -1;
while (curwin->w_skipcol > 0
&& curwin->w_topline < curbuf->b_ml.ml_line_count)
+   {
scroll_redraw(fixdir == FORWARD, 1);
+   *curscount += (fixdir == dir ? 1 : -1);
+   }
 }
 curwin->w_p_sms = prev_sms;
 
@@ -3220,7 +3224,7 @@ pagescroll(int dir, long count, int half)
curwin->w_p_scr = MIN(curwin->w_height, count);
count = MIN(curwin->w_height, curwin->w_p_scr);
 
-   int curscount = count;
+   long curscount = count;
// Adjust count so as to not reveal end of buffer lines.
if (dir == FORWARD
&& (curwin->w_topline + curwin->w_height + count > buflen
@@ -3240,7 +3244,7 @@ pagescroll(int dir, long count, int half)
// (Try to) scroll the window unless already at the end of the buffer.
if (count > 0)
{
-   nochange = scroll_with_sms(dir, count);
+   nochange = scroll_with_sms(dir, count, );
curwin->w_cursor.lnum = prev_lnum;
curwin->w_cursor.col = prev_col;
curwin->w_curswant = prev_curswant;
@@ -3259,7 +3263,7 @@ pagescroll(int dir, long count, int half)
// Scroll [count] times 'window' or current window height lines.
count *= ((ONE_WINDOW && p_window > 0 && p_window < Rows - 1) ?
MAX(1, p_window - 2) : get_scroll_overlap(dir));
-   nochange = scroll_with_sms(dir, count);
+   nochange = scroll_with_sms(dir, count, );
 
// Place cursor at top or bottom of window.
validate_botline();
diff --git a/src/testdir/test_normal.vim b/src/testdir/test_normal.vim
index 4b7e5e614..5cbf681ea 100644
--- a/src/testdir/test_normal.vim
+++ b/src/testdir/test_normal.vim
@@ -4260,4 +4260,12 @@ func Test_page_cursor_topbot()
   bwipe!
 endfunc
 
+" Test for Ctrl-D with long line
+func Test_halfpage_longline()
+  10new
+  call setline(1, ['long'->repeat(1000), 'short'])
+  exe "norm! \"
+  call assert_equal(2, line('.'))
+  bwipe!
+endfunc
 " vim: shiftwidth=2 sts=2 expandtab nofoldenable
diff --git a/src/version.c b/src/version.c
index e601c8217..828b3c78b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+407,
 /**/
 406,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1s5jHq-00CARb-WE%40256bit.org.


Commit: patch 9.1.0406: Divide by zero with getmousepos() and 'smoothscroll'

2024-05-11 Fir de Conversatie Christian Brabandt
patch 9.1.0406: Divide by zero with getmousepos() and 'smoothscroll'

Commit: 
https://github.com/vim/vim/commit/031a745608d615d56f9d79bb0f76e2a74b2eaf14
Author: zeertzjq 
Date:   Sat May 11 11:23:37 2024 +0200

patch 9.1.0406: Divide by zero with getmousepos() and 'smoothscroll'

Problem:  Divide by zero with getmousepos() and 'smoothscroll'.
Solution: Don't compute skip_lines when width1 is zero.
  (zeertzjq)

closes: #14747

Signed-off-by: zeertzjq 
Signed-off-by: Christian Brabandt 

diff --git a/src/mouse.c b/src/mouse.c
index 247c6df8e..4e10e723e 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -3029,16 +3029,22 @@ mouse_comp_pos(
 
if (win->w_skipcol > 0 && lnum == win->w_topline)
{
-   // Adjust for 'smoothscroll' clipping the top screen lines.
-   // A similar formula is used in curs_columns().
int width1 = win->w_width - win_col_off(win);
-   int skip_lines = 0;
-   if (win->w_skipcol > width1)
-   skip_lines = (win->w_skipcol - width1)
+
+   if (width1 > 0)
+   {
+   int skip_lines = 0;
+
+   // Adjust for 'smoothscroll' clipping the top screen lines.
+   // A similar formula is used in curs_columns().
+   if (win->w_skipcol > width1)
+   skip_lines = (win->w_skipcol - width1)
/ (width1 + win_col_off2(win)) + 1;
-   else if (win->w_skipcol > 0)
-   skip_lines = 1;
-   count -= skip_lines;
+   else if (win->w_skipcol > 0)
+   skip_lines = 1;
+
+   count -= skip_lines;
+   }
}
 
if (count > row)
diff --git a/src/move.c b/src/move.c
index 6790192ab..797184812 100644
--- a/src/move.c
+++ b/src/move.c
@@ -2617,12 +2617,14 @@ scroll_cursor_bot(int min_scroll, int set_topbot)
plines_win
 #endif
(curwin, curwin->w_topline, FALSE);
-   int skip_lines = 0;
int width1 = curwin->w_width - curwin_col_off();
+
if (width1 > 0)
{
int width2 = width1 + curwin_col_off2();
-   // similar formula is used in curs_columns()
+   int skip_lines = 0;
+
+   // A similar formula is used in curs_columns().
if (curwin->w_skipcol > width1)
skip_lines += (curwin->w_skipcol - width1) / width2 + 1;
else if (curwin->w_skipcol > 0)
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index f0d738582..5adbb42e6 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -3697,6 +3697,73 @@ func Test_getmousepos()
 \ column: 8,
 \ coladd: 21,
 \ }, getmousepos())
+
+  30vnew
+  setlocal smoothscroll number
+  call setline(1, join(range(100)))
+  exe "normal! \"
+  call test_setmouse(1, 5)
+  call assert_equal(#{
+\ screenrow: 1,
+\ screencol: 5,
+\ winid: win_getid(),
+\ winrow: 1,
+\ wincol: 5,
+\ line: 1,
+\ column: 27,
+\ coladd: 0,
+\ }, getmousepos())
+  call test_setmouse(2, 5)
+  call assert_equal(#{
+\ screenrow: 2,
+\ screencol: 5,
+\ winid: win_getid(),
+\ winrow: 2,
+\ wincol: 5,
+\ line: 1,
+\ column: 53,
+\ coladd: 0,
+\ }, getmousepos())
+
+  exe "normal! \"
+  call test_setmouse(1, 5)
+  call assert_equal(#{
+\ screenrow: 1,
+\ screencol: 5,
+\ winid: win_getid(),
+\ winrow: 1,
+\ wincol: 5,
+\ line: 1,
+\ column: 53,
+\ coladd: 0,
+\ }, getmousepos())
+  call test_setmouse(2, 5)
+  call assert_equal(#{
+\ screenrow: 2,
+\ screencol: 5,
+\ winid: win_getid(),
+\ winrow: 2,
+\ wincol: 5,
+\ line: 1,
+\ column: 79,
+\ coladd: 0,
+\ }, getmousepos())
+
+  vert resize 4
+  call test_setmouse(2, 2)
+  " This used to crash Vim
+  call assert_equal(#{
+\ screenrow: 2,
+\ screencol: 2,
+\ winid: win_getid(),
+\ winrow: 2,
+\ wincol: 2,
+\ line: 1,
+\ column: 53,
+\ coladd: 0,
+\ }, getmousepos())
+
+  bwipe!
   bwipe!
 endfunc
 
diff --git a/src/version.c b/src/version.c
index cbd29097d..e601c8217 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+406,
 /**/
 405,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to 

Commit: runtime(doc): update and remove some invalid links

2024-05-11 Fir de Conversatie Christian Brabandt
runtime(doc): update and remove  some invalid links

Commit: 
https://github.com/vim/vim/commit/1c5728e0c4a9df930879f9f0ca108092d5902194
Author: Christian Brabandt 
Date:   Sat May 11 11:12:40 2024 +0200

runtime(doc): update and remove  some invalid links

closes: https://github.com/vim/vim/issues/14748

Co-authored-by: zeertzjq 
Signed-off-by: Christian Brabandt 

diff --git a/runtime/doc/debug.txt b/runtime/doc/debug.txt
index 1d3090af8..4963fdd03 100644
--- a/runtime/doc/debug.txt
+++ b/runtime/doc/debug.txt
@@ -1,4 +1,4 @@
-*debug.txt* For Vim version 9.1.  Last change: 2019 May 07
+*debug.txt* For Vim version 9.1.  Last change: 2024 May 11
 
 
  VIM REFERENCE MANUALby Bram Moolenaar
@@ -160,7 +160,7 @@ In WinDbg: choose Open Crash Dump on the File menu. Follow 
the instructions in
 3.5 Obtaining Microsoft Debugging Tools ~
 
 The Debugging Tools for Windows (including WinDbg) can be downloaded from
-http://www.microsoft.com/whdc/devtools/debugging/default.mspx
+
https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-download-tools
 This includes the WinDbg debugger.
 
 Visual C++ 2005 Express Edition can be downloaded for free from:
diff --git a/runtime/doc/develop.txt b/runtime/doc/develop.txt
index 1b1ad8561..678a92461 100644
--- a/runtime/doc/develop.txt
+++ b/runtime/doc/develop.txt
@@ -1,4 +1,4 @@
-*develop.txt*   For Vim version 9.1.  Last change: 2022 Sep 20
+*develop.txt*   For Vim version 9.1.  Last change: 2024 May 11
 
 
  VIM REFERENCE MANUALby Bram Moolenaar
@@ -152,7 +152,7 @@ VIM IS... NOT   
*design-not*
   everything but the kitchen sink, but some people say that you can clean one
   with it.  ;-)"
   To use Vim with gdb see |terminal-debugger|.  Other (older) tools can be
-  found at http://www.agide.org and http://clewn.sf.net.
+  found at http://www.agide.org (link seems dead)  and http://clewn.sf.net.
 - Vim is not a fancy GUI editor that tries to look nice at the cost of
   being less consistent over all platforms.  But functional GUI features are
   welcomed.
diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt
index de33c9caa..3b559196b 100644
--- a/runtime/doc/gui.txt
+++ b/runtime/doc/gui.txt
@@ -1,4 +1,4 @@
-*gui.txt*   For Vim version 9.1.  Last change: 2024 May 01
+*gui.txt*   For Vim version 9.1.  Last change: 2024 May 11
 
 
  VIM REFERENCE MANUALby Bram Moolenaar
@@ -1238,7 +1238,8 @@ This section describes other features which are related 
to the GUI.
endif
 
 A recommended Japanese font is MS Mincho.  You can find info here:
-http://www.lexikan.com/mincho.htm
+https://learn.microsoft.com/en-us/typography/font-list/ms-mincho
+It should be distributed with Windows.
 
 ==
 8. Shell Commands  *gui-shell*
diff --git a/runtime/doc/if_cscop.txt b/runtime/doc/if_cscop.txt
index 3fa8f817f..bb4c6a18d 100644
--- a/runtime/doc/if_cscop.txt
+++ b/runtime/doc/if_cscop.txt
@@ -1,4 +1,4 @@
-*if_cscop.txt*  For Vim version 9.1.  Last change: 2022 Jan 08
+*if_cscop.txt*  For Vim version 9.1.  Last change: 2024 May 11
 
 
  VIM REFERENCE MANUALby Andy Kahn
@@ -358,7 +358,7 @@ system calls: fork(), pipe(), execl(), waitpid().  This 
means it is mostly
 limited to Unix systems.
 
 Additionally Cscope support works for Win32.  For more information and a
-cscope version for Win32 see:
+cscope version for Win32 see (link seems dead):
 
http://iamphet.nm.ru/cscope/index.html
 
diff --git a/runtime/doc/mbyte.txt b/runtime/doc/mbyte.txt
index 91154a744..e38c30cb1 100644
--- a/runtime/doc/mbyte.txt
+++ b/runtime/doc/mbyte.txt
@@ -1,4 +1,4 @@
-*mbyte.txt* For Vim version 9.1.  Last change: 2022 Apr 03
+*mbyte.txt* For Vim version 9.1.  Last change: 2024 May 11
 
 
  VIM REFERENCE MANUALby Bram Moolenaar et al.
@@ -451,18 +451,19 @@ Useful utilities for converting the charset:
 Chinese:   hc
Hc is "Hanzi Converter".  Hc convert a GB file to a Big5 file, or Big5
file to GB file.  Hc can be found at:
+   https://www.freshports.org/chinese/hc
ftp://ftp.cuhk.hk/pub/chinese/ifcss/software/unix/convert/hc-30.tar.gz
 
 Korean:hmconv
Hmconv is Korean code conversion utility especially for E-mail.  It can
convert between EUC-KR and ISO-2022-KR.  Hmconv can be found at:
-   ftp://ftp.kaist.ac.kr/pub/hangul/code/hmconv/
+   https://www.freshports.org/korean/hmconv/
 
 Multilingual:   lv
Lv is a Powerful Multilingual File Viewer.  And it can be worked as
|charset| converter.  Supported |charset|: ISO-2022-CN, ISO-2022-JP,
ISO-2022-KR, EUC-CN, EUC-JP, EUC-KR, EUC-TW, UTF-7, UTF-8, ISO-8859
-   series, Shift_JIS, Big5 and HZ.  Lv can be found at:
+   series,