Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c554505

Browse files
committed
Trent Mick:
Fix overflow bug in ldexp(x, exp). The 'exp' argument maps to a C int for the math library call [double ldexp(double, int)], however the 'd' PyArg_ParseTuple formatter was used to yield a double, which was subsequently cast to an int. This could overflow. [GvR: mysteriously, on Solaris 2.7, ldexp(1, 2147483647) returns Inf while ldexp(1, 2147483646) raises OverflowError; this seems a bug in the math library (it also takes a real long time to compute the Inf outcome). Does this point to a bug in the CHECK() macro? It should have discovered that the result was outside the HUGE_VAL range.]
1 parent 23ef82f commit c554505

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Modules/mathmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ math_ldexp(self, args)
196196
PyObject *self;
197197
PyObject *args;
198198
{
199-
double x, y;
200-
/* Cheat -- allow float as second argument */
201-
if (! PyArg_Parse(args, "(dd)", &x, &y))
199+
double x;
200+
int exp;
201+
if (! PyArg_Parse(args, "(di)", &x, &exp))
202202
return NULL;
203203
errno = 0;
204204
PyFPE_START_PROTECT("ldexp", return 0)
205-
x = ldexp(x, (int)y);
205+
x = ldexp(x, exp);
206206
PyFPE_END_PROTECT(x)
207207
CHECK(x);
208208
if (errno != 0)

0 commit comments

Comments
 (0)