patch 8.0.0219: ubsan reports errors for overflow
Problem: Ubsan reports errors for integer overflow.
Solution: Define macros for minimum and maximum values. Select an
expression based on the value. (Mike Williams)
diff --git a/src/eval.c b/src/eval.c
index f70d03b..5846936 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -4109,21 +4109,12 @@
{
if (n2 == 0) /* give an error message? */
{
-#ifdef FEAT_NUM64
if (n1 == 0)
- n1 = -0x7fffffffffffffffLL - 1; /* similar to NaN */
+ n1 = VARNUM_MIN; /* similar to NaN */
else if (n1 < 0)
- n1 = -0x7fffffffffffffffLL;
+ n1 = -VARNUM_MAX;
else
- n1 = 0x7fffffffffffffffLL;
-#else
- if (n1 == 0)
- n1 = -0x7fffffffL - 1L; /* similar to NaN */
- else if (n1 < 0)
- n1 = -0x7fffffffL;
- else
- n1 = 0x7fffffffL;
-#endif
+ n1 = VARNUM_MAX;
}
else
n1 = n1 / n2;