vim-patch:8.1.0048: vim_str2nr() on numbers close to max #9744

Problem:    vim_str2nr() does not handle numbers close to the maximum.
Solution:   Check for overflow more precisely. (Ken Takata, closes vim/vim#2746)
07ccf7ce7f
This commit is contained in:
Jan Edmund Lazo 2019-03-17 17:08:01 -04:00 committed by Justin M. Keyes
parent 027a2157d3
commit d86c816f8c

View File

@ -1777,9 +1777,12 @@ void vim_str2nr(const char_u *const start, int *const prep, int *const len,
#define PARSE_NUMBER(base, cond, conv) \ #define PARSE_NUMBER(base, cond, conv) \
do { \ do { \
while (!STRING_ENDED(ptr) && (cond)) { \ while (!STRING_ENDED(ptr) && (cond)) { \
const uvarnumber_T digit = (uvarnumber_T)(conv); \
/* avoid ubsan error for overflow */ \ /* avoid ubsan error for overflow */ \
if (un < UVARNUMBER_MAX / base) { \ if (un < UVARNUMBER_MAX / base \
un = base * un + (uvarnumber_T)(conv); \ || (un == UVARNUMBER_MAX / base \
&& (base != 10 || digit <= UVARNUMBER_MAX % 10))) { \
un = base * un + digit; \
} else { \ } else { \
un = UVARNUMBER_MAX; \ un = UVARNUMBER_MAX; \
} \ } \