diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-07 18:35:03 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2017-09-07 18:35:03 (GMT) |
commit | b03623227ed1264e3cac4e6bb4878d96b91aa484 (patch) | |
tree | 019511e476f77bf6ed4e2cbfd9c8280ff89d9e96 /Objects/floatobject.c | |
parent | b0d0217c0e4c1512a06ef306928b2fd8f82d046e (diff) | |
download | cpython-b03623227ed1264e3cac4e6bb4878d96b91aa484.zip cpython-b03623227ed1264e3cac4e6bb4878d96b91aa484.tar.gz cpython-b03623227ed1264e3cac4e6bb4878d96b91aa484.tar.bz2 |
[3.6] fixes bpo-31373: fix undefined floating-point demotions (GH-3396) (#3424)
(cherry picked from commit a853a8ba7850381d49b284295dd6f0dc491dbe44)
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r-- | Objects/floatobject.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 80bf71e..1803a68 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -2182,13 +2182,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; @@ -2196,7 +2198,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; |