File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -124,10 +124,15 @@ maybe_small_long(PyLongObject *v)
124124 return _PyLong_FromMedium((sdigit)(ival)); \
125125 } \
126126 /* Count digits (at least two - smaller cases were handled above). */ \
127- size_t abs_ival , t ; /* Use size_t for unsigned operations */ \
127+ size_t abs_ival ; /* Use size_t for unsigned operations */ \
128+ size_t t ; \
128129 if ((ival ) < 0 ) { \
129- /* avoid signed overflow when ival = minimum value */ \
130- abs_ival = (size_t )(-1 - (ival ))+ 1 ; \
130+ /* Handle minimum value case separately to avoid overflow */ \
131+ if ((ival ) == - (INT_TYPE )((size_t )1 << (sizeof (INT_TYPE ) * 8 - 1 ))) { \
132+ abs_ival = (size_t )1 << (sizeof (INT_TYPE ) * 8 - 1 ); \
133+ } else { \
134+ abs_ival = (size_t )(- (ival )); \
135+ } \
131136 } else { \
132137 abs_ival = (size_t )(ival ); \
133138 } \
You can’t perform that action at this time.
0 commit comments