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/ops.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/ops.c')
-rw-r--r-- | src/nvim/ops.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 6929189750..1a33ae8bbf 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4658,11 +4658,12 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) : length); } + bool overflow = false; vim_str2nr(ptr + col, &pre, &length, 0 + (do_bin ? STR2NR_BIN : 0) + (do_oct ? STR2NR_OCT : 0) + (do_hex ? STR2NR_HEX : 0), - NULL, &n, maxlen, false); + NULL, &n, maxlen, false, &overflow); // ignore leading '-' for hex, octal and bin numbers if (pre && negative) { @@ -4682,8 +4683,10 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) oldn = n; - n = subtract ? n - (uvarnumber_T)Prenum1 - : n + (uvarnumber_T)Prenum1; + if (!overflow) { // if number is too big don't add/subtract + n = subtract ? n - (uvarnumber_T)Prenum1 + : n + (uvarnumber_T)Prenum1; + } // handle wraparound for decimal numbers if (!pre) { |