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

@ -2233,13 +2233,15 @@ _PyFloat_Pack4(double x, unsigned char *p, int le)
}
else {
float y = (float)x;
const unsigned char *s = (unsigned char*)&y;
int i, incr = 1;
if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x))
if (fabs(x) > FLT_MAX && !Py_IS_INFINITY(x))
goto Overflow;
unsigned char s[sizeof(float)];
float y = (float)x;
memcpy(s, &y, sizeof(float));
if ((float_format == ieee_little_endian_format && !le)
|| (float_format == ieee_big_endian_format && le)) {
p += 3;
@ -2247,7 +2249,7 @@ _PyFloat_Pack4(double x, unsigned char *p, int le)
}
for (i = 0; i < 4; i++) {
*p = *s++;
*p = s[i];
p += incr;
}
return 0;