From a371f1027e443e59a54191b187170b63fcf94a9b Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 2 Sep 2016 10:02:49 -0400 Subject: [PATCH] Fix error-handling of strtoimax boundary conditions strtoimax is only required to set errno if there is an underflow/overflow. In those conditions, strtoimax returns INTMAX_MIN/INTMAX_MAX respectively, so that's the only time we should be checking the value of errno. Even in those conditions, errno needs to be set to a known good value before calling strtoimax to differentiate between "value is actually INTMAX_MAX/MIN" and "value over/underflows". Closes #5279 --- src/nvim/charset.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 22ca0fb0cc..b5154819b9 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -1739,8 +1739,11 @@ char_u* skiptowhite_esc(char_u *p) { /// @return Number read from the string. intmax_t getdigits(char_u **pp) { + errno = 0; intmax_t number = strtoimax((char *)*pp, (char **)pp, 10); - assert(errno != ERANGE); + if (number == INTMAX_MAX || number == INTMAX_MIN) { + assert(errno != ERANGE); + } return number; }