Mercurial > vim
diff src/ops.c @ 32098:39f4126d2a0d v9.0.1380
patch 9.0.1380: CTRL-X on 2**64 subtracts two
Commit: https://github.com/vim/vim/commit/5fb78c3fa5c996c08a65431d698bd2c251eef5c7
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 4 20:47:39 2023 +0000
patch 9.0.1380: CTRL-X on 2**64 subtracts two
Problem: CTRL-X on 2**64 subtracts two. (James McCoy)
Solution: Correct computation for large number. (closes https://github.com/vim/vim/issues/12103)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 04 Mar 2023 22:00:03 +0100 |
parents | ca6bc7c04163 |
children | ffbae151e462 |
line wrap: on
line diff
--- a/src/ops.c +++ b/src/ops.c @@ -2781,11 +2781,12 @@ do_addsub( ? (int)STRLEN(ptr) - col : length); + int 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 and octal and bin numbers if (pre && negative) @@ -2802,10 +2803,14 @@ do_addsub( subtract ^= TRUE; oldn = n; - if (subtract) - n -= (uvarnumber_T)Prenum1; - else - n += (uvarnumber_T)Prenum1; + if (!overflow) // if number is too big don't add/subtract + { + if (subtract) + n -= (uvarnumber_T)Prenum1; + else + n += (uvarnumber_T)Prenum1; + } + // handle wraparound for decimal numbers if (!pre) {