diff options
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) { |