diff options
author | Ernie Rael <errael@raelity.com> | 2023-11-23 20:21:45 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-11-23 20:33:05 +0100 |
commit | 2b0882fa6555b4d0197afbdfc32a4533cf6aacf4 (patch) | |
tree | b8467231938c30e9391beb2f363f2a82fe872cb3 /src/misc1.c | |
parent | df63da98d8dc284b1c76cfe1b17fa0acbd6094d8 (diff) |
patch 9.0.2124: INT overflow detection logic can be simplifiedv9.0.2124
Problem: INT overflow logic can be simplified
Solution: introduce trim_to_int() function
closes: #13556
Signed-off-by: Ernie Rael <errael@raelity.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/misc1.c b/src/misc1.c index dc0deae67a..a82ef9cd93 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -2838,3 +2838,11 @@ vim_append_digit_long(long *value, int digit) *value = x * 10 + (long)digit; return OK; } + +// Return something that fits into an int. + int +trim_to_int(long long x) +{ + return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : x; +} + |