summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2017-09-07 18:13:59 (GMT)
committerGitHub <noreply@github.com>2017-09-07 18:13:59 (GMT)
commita853a8ba7850381d49b284295dd6f0dc491dbe44 (patch)
treedb901475288d8942c221c336fc4ad61f596761c3 /Objects
parentc988ae01fec2e0510d53728e01a5e4bb06761bda (diff)
downloadcpython-a853a8ba7850381d49b284295dd6f0dc491dbe44.zip
cpython-a853a8ba7850381d49b284295dd6f0dc491dbe44.tar.gz
cpython-a853a8ba7850381d49b284295dd6f0dc491dbe44.tar.bz2
bpo-31373: fix undefined floating-point demotions (#3396)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 8c4fe74..fc1ddf4 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -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;