We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a584478 commit b292561Copy full SHA for b292561
Include/pymacro.h
@@ -115,8 +115,13 @@
115
#define Py_MAX(x, y) (((x) > (y)) ? (x) : (y))
116
117
/* Absolute value of the number x */
118
-#define _Py_ABS_CAST(T,x) ((x) >= 0 ? ((T) (x)) : (- (((T) ((x) + 1)) - 1)))
119
#define Py_ABS(x) ((x) < 0 ? -(x) : (x))
+/* Safer implementation that avoids an undefined behavior for the minimal
120
+ value of the signed integer type if its absolute value is larger than
121
+ the maximal value of the signed integer type (in the two's complement
122
+ representations, which is common).
123
+ */
124
+#define _Py_ABS_CAST(T, x) ((x) >= 0 ? ((T) (x)) : ((T) (((T) -((x) + 1)) + 1u)))
125
126
#define _Py_XSTRINGIFY(x) #x
127
0 commit comments