summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMeekail Zain <34613774+Micky774@users.noreply.github.com>2022-06-03 13:53:34 -0400
committerGitHub <noreply@github.com>2022-06-03 10:53:34 -0700
commit0435145f173d88cf928d346438abf8a8f5515eda (patch)
tree04025b21ab4683a52d8fb52b72271f27cf6ecaf6
parentc994325c1c57e19ee467ebc9db163506086c58f6 (diff)
downloadnumpy-0435145f173d88cf928d346438abf8a8f5515eda.tar.gz
MAINT: improved overflow check to avoid undefined behavior (#21658)
* MAINT: improved overflow check to avoid undefined behavior * Fixed template * Simplified check
-rw-r--r--numpy/core/src/umath/scalarmath.c.src4
1 files changed, 3 insertions, 1 deletions
diff --git a/numpy/core/src/umath/scalarmath.c.src b/numpy/core/src/umath/scalarmath.c.src
index 8fb219b63..4993546f8 100644
--- a/numpy/core/src/umath/scalarmath.c.src
+++ b/numpy/core/src/umath/scalarmath.c.src
@@ -156,6 +156,8 @@ static NPY_INLINE int
* #type = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* npy_long, npy_ulong, npy_longlong, npy_ulonglong#
* #neg = (1,0)*5#
+ * #NAME = BYTE, UBYTE, SHORT, USHORT, INT, UINT,
+ * LONG, ULONG, LONGLONG, ULONGLONG#
*/
static NPY_INLINE int
@name@_ctype_divide(@type@ a, @type@ b, @type@ *out) {
@@ -164,7 +166,7 @@ static NPY_INLINE int
return NPY_FPE_DIVIDEBYZERO;
}
#if @neg@
- else if (b == -1 && a < 0 && a == -a) {
+ else if (b == -1 && a == NPY_MIN_@NAME@) {
*out = a / b;
return NPY_FPE_OVERFLOW;
}