diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-04-11 09:34:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-11 09:34:43 +0800 |
commit | 7aa56370f326f5f1b3fdfa1c79bbffc7cc6ae267 (patch) | |
tree | 3e01c5c1e5e883cfa7d517670ac5ab1a10042ac8 /src/nvim/input.c | |
parent | 4528a69c8772a5fe182fb293b929dfcfad112abc (diff) | |
download | rneovim-7aa56370f326f5f1b3fdfa1c79bbffc7cc6ae267.tar.gz rneovim-7aa56370f326f5f1b3fdfa1c79bbffc7cc6ae267.tar.bz2 rneovim-7aa56370f326f5f1b3fdfa1c79bbffc7cc6ae267.zip |
vim-patch:9.0.2114: overflow detection not accurate when adding digits (#28271)
Problem: overflow detection not accurate when adding digits
Solution: Use a helper function
Use a helper function to better detect overflows before adding integer
digits to a long or an integer variable respectively. Signal the
overflow to the caller function.
closes: vim/vim#13539
https://github.com/vim/vim/commit/22cbc8a4e17ce61aa460c451a26e1bff2c3d2af9
Co-authored-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/nvim/input.c')
-rw-r--r-- | src/nvim/input.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/nvim/input.c b/src/nvim/input.c index 7667c49452..e14bfe7539 100644 --- a/src/nvim/input.c +++ b/src/nvim/input.c @@ -14,6 +14,7 @@ #include "nvim/highlight_defs.h" #include "nvim/input.h" #include "nvim/keycodes.h" +#include "nvim/math.h" #include "nvim/mbyte.h" #include "nvim/memory.h" #include "nvim/message.h" @@ -21,6 +22,7 @@ #include "nvim/os/input.h" #include "nvim/state_defs.h" #include "nvim/ui.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "input.c.generated.h" // IWYU pragma: export @@ -180,10 +182,9 @@ int get_number(int colon, bool *mouse_used) ui_cursor_goto(msg_row, msg_col); int c = safe_vgetc(); if (ascii_isdigit(c)) { - if (n > INT_MAX / 10) { + if (vim_append_digit_int(&n, c - '0') == FAIL) { return 0; } - n = n * 10 + c - '0'; msg_putchar(c); typed++; } else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H) { |