bpo-31373: fix undefined floating-point demotions (#3396)

This commit is contained in:
Benjamin Peterson 2017-09-07 11:13:59 -07:00 committed by GitHub
parent c988ae01fe
commit a853a8ba78
5 changed files with 51 additions and 30 deletions

View file

@ -4,6 +4,7 @@
#include "Python.h"
#include <ctype.h>
#include <float.h>
#ifdef __cplusplus
@ -858,6 +859,10 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
double dval = PyFloat_AsDouble(arg);
if (PyErr_Occurred())
RETURN_ERR_OCCURRED;
else if (dval > FLT_MAX)
*p = (float)INFINITY;
else if (dval < -FLT_MAX)
*p = (float)-INFINITY;
else
*p = (float) dval;
break;