[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] [PATCH 1/1] ZeroDivide bug in float printing
From: |
Derek Zhou |
Subject: |
[Help-smalltalk] [PATCH 1/1] ZeroDivide bug in float printing |
Date: |
Fri, 29 Mar 2019 11:43:28 +0800 |
User-agent: |
mu4e 0.9.18; emacs 24.5.1 |
To fix 64bit mode integer multiply overflow detection.
This method should be more robust wrt. compiler optimization
diff --git a/libgst/interp.inl b/libgst/interp.inl
index dbc631b..3583b19 100644
--- a/libgst/interp.inl
+++ b/libgst/interp.inl
@@ -199,15 +199,23 @@ mul_with_check (OOP op1, OOP op2, mst_Boolean *overflow)
/* This fallback method uses a division to do overflow check */
else
{
- if COMMON ((((uintptr_t) (a | b)) < (1L << (ST_INT_SIZE / 2))
- || b == 0
- || result / b == a)
- && !INT_OVERFLOW (result))
- return FROM_INT (result);
- else
- *overflow = true;
+ intptr_t abs_a = ABS (a);
+ intptr_t abs_b = ABS (b);
+ intptr_t limit = (1L << (ST_INT_SIZE / 2 - 1));
+ if (COMMON ( abs_a < limit && abs_b < limit ))
+ goto legal;
+ if (UNCOMMON (b == 0L))
+ goto legal;
+ if (UNCOMMON (INT_OVERFLOW (result)))
+ goto overflow;
+ if (UNCOMMON (MAX_ST_INT / abs_b < abs_a))
+ goto overflow;
+ legal:
+ return FROM_INT (result);
}
+ overflow:
+ *overflow = true;
return FROM_INT (0);
#endif
}