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

@@ -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) {