[Python-checkins] CVS: python/dist/src/Modules mathmodule.c,2.42,2.43
Guido van Rossum
python-dev@python.org
Mon, 8 May 2000 10:29:41 -0400 (EDT)
Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/projects/python/develop/guido/src/Modules
Modified Files:
mathmodule.c
Log Message:
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.]
Index: mathmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/mathmodule.c,v
retrieving revision 2.42
retrieving revision 2.43
diff -C2 -r2.42 -r2.43
*** mathmodule.c 1998年12月08日 16:27:10 2.42
--- mathmodule.c 2000年05月08日 14:29:38 2.43
***************
*** 197,207 ****
PyObject *args;
{
! double x, y;
! /* Cheat -- allow float as second argument */
! if (! PyArg_Parse(args, "(dd)", &x, &y))
return NULL;
errno = 0;
PyFPE_START_PROTECT("ldexp", return 0)
! x = ldexp(x, (int)y);
PyFPE_END_PROTECT(x)
CHECK(x);
--- 197,207 ----
PyObject *args;
{
! double x;
! int exp;
! if (! PyArg_Parse(args, "(di)", &x, &exp))
return NULL;
errno = 0;
PyFPE_START_PROTECT("ldexp", return 0)
! x = ldexp(x, exp);
PyFPE_END_PROTECT(x)
CHECK(x);