Mercurial > vim
comparison src/misc1.c @ 33817:4550abd680b6 v9.0.2124
patch 9.0.2124: INT overflow detection logic can be simplified
Commit: https://github.com/vim/vim/commit/2b0882fa6555b4d0197afbdfc32a4533cf6aacf4
Author: Ernie Rael <errael@raelity.com>
Date: Thu Nov 23 20:21:45 2023 +0100
patch 9.0.2124: INT overflow detection logic can be simplified
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>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 23 Nov 2023 20:45:04 +0100 |
parents | 370543108ba1 |
children | 68de519bab0a |
comparison
equal
deleted
inserted
replaced
33816:2948c0b4f087 | 33817:4550abd680b6 |
---|---|
2836 if (x > ((LONG_MAX - (long)digit) / 10)) | 2836 if (x > ((LONG_MAX - (long)digit) / 10)) |
2837 return FAIL; | 2837 return FAIL; |
2838 *value = x * 10 + (long)digit; | 2838 *value = x * 10 + (long)digit; |
2839 return OK; | 2839 return OK; |
2840 } | 2840 } |
2841 | |
2842 // Return something that fits into an int. | |
2843 int | |
2844 trim_to_int(long long x) | |
2845 { | |
2846 return x > INT_MAX ? INT_MAX : x < INT_MIN ? INT_MIN : x; | |
2847 } | |
2848 |