Skip to content

Commit dd431b3

Browse files
authored
PyLong_FromString(): fix Coverity CID 1424951 (#4738)
Explicitly cast digits (Py_ssize_t) to double to fix the following false-alarm warning from Coverity: "fsize_z = digits * log_base_BASE[base] + 1;" CID 1424951: Incorrect expression (UNINTENDED_INTEGER_DIVISION) Dividing integer expressions "9223372036854775783UL" and "4UL", and then converting the integer quotient to type "double". Any remainder, or fractional part of the quotient, is ignored.
1 parent a0374dd commit dd431b3

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Objects/longobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,6 @@ just 1 digit at the start, so that the copying code was exercised for every
22672267
digit beyond the first.
22682268
***/
22692269
twodigits c; /* current input character */
2270-
double fsize_z;
22712270
Py_ssize_t size_z;
22722271
Py_ssize_t digits = 0;
22732272
int i;
@@ -2331,8 +2330,8 @@ digit beyond the first.
23312330
* need to initialize z->ob_digit -- no slot is read up before
23322331
* being stored into.
23332332
*/
2334-
fsize_z = digits * log_base_BASE[base] + 1;
2335-
if (fsize_z > MAX_LONG_DIGITS) {
2333+
double fsize_z = (double)digits * log_base_BASE[base] + 1.0;
2334+
if (fsize_z > (double)MAX_LONG_DIGITS) {
23362335
/* The same exception as in _PyLong_New(). */
23372336
PyErr_SetString(PyExc_OverflowError,
23382337
"too many digits in integer");

0 commit comments

Comments
 (0)