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>
diff --git a/src/misc1.c b/src/misc1.c
index dc0deae..a82ef9c 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -2838,3 +2838,11 @@
*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;
+}
+