0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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 #12103)
This commit is contained in:
Bram Moolenaar
2023-03-04 20:47:39 +00:00
parent 5284b23e14
commit 5fb78c3fa5
12 changed files with 69 additions and 21 deletions

View File

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