diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-03-05 09:18:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-05 09:18:42 +0800 |
commit | 419819b6245e120aba8897e3ddea711b2cd0246c (patch) | |
tree | 6a86105155ec9abc9553d3ed69a30321f4be9a01 /src/nvim/charset.c | |
parent | b44b8e7687ece66f4c535182071223d78ca54ad0 (diff) | |
download | rneovim-419819b6245e120aba8897e3ddea711b2cd0246c.tar.gz rneovim-419819b6245e120aba8897e3ddea711b2cd0246c.tar.bz2 rneovim-419819b6245e120aba8897e3ddea711b2cd0246c.zip |
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)
https://github.com/vim/vim/commit/5fb78c3fa5c996c08a65431d698bd2c251eef5c7
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/charset.c')
-rw-r--r-- | src/nvim/charset.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/nvim/charset.c b/src/nvim/charset.c index bf18d110c0..b792ae5ece 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -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; } |