mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-31373: fix undefined floating-point demotions (#3396)
This commit is contained in:
parent
c988ae01fe
commit
a853a8ba78
5 changed files with 51 additions and 30 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue