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

Skip to content

Commit fe4b6ee

Browse files
committed
Include mymath.h instead of declaring prototypes for math functions.
Fix leak and unchecked error in complex().
1 parent 1d60614 commit fe4b6ee

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Python/bltinmodule.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3333
#include "compile.h"
3434
#include "eval.h"
3535

36+
#include "mymath.h"
37+
3638
/* Forward */
3739
static object *filterstring PROTO((object *, object *));
3840
static object *filtertuple PROTO((object *, object *));
@@ -284,7 +286,7 @@ builtin_complex(self, args)
284286
object *self;
285287
object *args;
286288
{
287-
object *r, *i;
289+
object *r, *i, *tmp;
288290
number_methods *nbr, *nbi;
289291
Py_complex cr, ci;
290292

@@ -302,7 +304,11 @@ builtin_complex(self, args)
302304
if (is_complexobject(r))
303305
cr = ((complexobject*)r)->cval;
304306
else {
305-
cr.real = getfloatvalue((*nbr->nb_float)(r));
307+
tmp = (*nbr->nb_float)(r);
308+
if (tmp == NULL)
309+
return NULL;
310+
cr.real = getfloatvalue(tmp);
311+
DECREF(tmp);
306312
cr.imag = 0.;
307313
}
308314
if (i == NULL) {
@@ -312,7 +318,11 @@ builtin_complex(self, args)
312318
else if (is_complexobject(i))
313319
ci = ((complexobject*)i)->cval;
314320
else {
315-
ci.real = getfloatvalue((*nbi->nb_float)(i));
321+
tmp = (*nbr->nb_float)(r);
322+
if (tmp == NULL)
323+
return NULL;
324+
ci.real = getfloatvalue(tmp);
325+
DECREF(tmp);
316326
ci.imag = 0.;
317327
}
318328
cr.real -= ci.imag;
@@ -1354,8 +1364,6 @@ builtin_round(self, args)
13541364
object *self;
13551365
object *args;
13561366
{
1357-
extern double floor PROTO((double));
1358-
extern double ceil PROTO((double));
13591367
double x;
13601368
double f;
13611369
int ndigits = 0;

0 commit comments

Comments
 (0)