@@ -1776,25 +1776,30 @@ vim_isblankline(char_u *lbuf)
17761776 * If "what" contains STR2NR_HEX recognize hex numbers
17771777 * If "what" contains STR2NR_FORCE always assume bin/oct/hex.
17781778 * If maxlen > 0, check at a maximum maxlen chars.
1779+ * If strict is TRUE, check the number strictly. return *len = 0 if fail.
17791780 */
17801781 void
17811782vim_str2nr (
17821783 char_u * start ,
1783- int * prep , /* return: type of number 0 = decimal, 'x'
1784- or 'X' is hex, '0' = octal, 'b' or 'B'
1785- is bin */
1786- int * len , /* return: detected length of number */
1787- int what , /* what numbers to recognize */
1788- varnumber_T * nptr , /* return: signed result */
1789- uvarnumber_T * unptr , /* return: unsigned result */
1790- int maxlen ) /* max length of string to check */
1784+ int * prep , // return: type of number 0 = decimal, 'x'
1785+ // or 'X' is hex, '0' = octal, 'b' or 'B'
1786+ // is bin
1787+ int * len , // return: detected length of number
1788+ int what , // what numbers to recognize
1789+ varnumber_T * nptr , // return: signed result
1790+ uvarnumber_T * unptr , // return: unsigned result
1791+ int maxlen , // max length of string to check
1792+ int strict ) // check strictly
17911793{
17921794 char_u * ptr = start ;
1793- int pre = 0 ; /* default is decimal */
1795+ int pre = 0 ; // default is decimal
17941796 int negative = FALSE;
17951797 uvarnumber_T un = 0 ;
17961798 int n ;
17971799
1800+ if (len != NULL )
1801+ * len = 0 ;
1802+
17981803 if (ptr [0 ] == '-' )
17991804 {
18001805 negative = TRUE;
@@ -1836,9 +1841,7 @@ vim_str2nr(
18361841 }
18371842 }
18381843
1839- /*
1840- * Do the string-to-numeric conversion "manually" to avoid sscanf quirks.
1841- */
1844+ // Do the conversion manually to avoid sscanf() quirks.
18421845 n = 1 ;
18431846 if (pre == 'B' || pre == 'b' || what == STR2NR_BIN + STR2NR_FORCE )
18441847 {
@@ -1907,6 +1910,10 @@ vim_str2nr(
19071910 break ;
19081911 }
19091912 }
1913+ // Check for an alpha-numeric character immediately following, that is
1914+ // most likely a typo.
1915+ if (strict && n - 1 != maxlen && ASCII_ISALNUM (* ptr ))
1916+ return ;
19101917
19111918 if (prep != NULL )
19121919 * prep = pre ;
0 commit comments