vim-patch:9.0.1380: CTRL-X on 2**64 subtracts two (#22530)

Problem:    CTRL-X on 2**64 subtracts two. (James McCoy)
Solution:   Correct computation for large number. (closes vim/vim#12103)

5fb78c3fa5

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq
2023-03-05 09:18:42 +08:00
committed by GitHub
parent b44b8e7687
commit 419819b624
13 changed files with 48 additions and 19 deletions

View File

@@ -1500,9 +1500,10 @@ bool vim_isblankline(char *lbuf)
/// @param strict If true, fail if the number has unexpected trailing
/// alphanumeric chars: *len is set to 0 and nothing else is
/// returned.
/// @param overflow When not NULL, set to true for overflow.
void vim_str2nr(const char *const start, int *const prep, int *const len, const int what,
varnumber_T *const nptr, uvarnumber_T *const unptr, const int maxlen,
const bool strict)
const bool strict, bool *const overflow)
FUNC_ATTR_NONNULL_ARG(1)
{
const char *ptr = start;
@@ -1626,6 +1627,9 @@ void vim_str2nr(const char *const start, int *const prep, int *const len, const
un = (base) * un + digit; \
} else { \
un = UVARNUMBER_MAX; \
if (overflow != NULL) { \
*overflow = true; \
} \
} \
ptr++; \
} \
@@ -1664,12 +1668,18 @@ vim_str2nr_proceed:
// avoid ubsan error for overflow
if (un > VARNUMBER_MAX) {
*nptr = VARNUMBER_MIN;
if (overflow != NULL) {
*overflow = true;
}
} else {
*nptr = -(varnumber_T)un;
}
} else {
if (un > VARNUMBER_MAX) {
un = VARNUMBER_MAX;
if (overflow != NULL) {
*overflow = true;
}
}
*nptr = (varnumber_T)un;
}