summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2005-12-05 00:27:49 (GMT)
committerMichael W. Hudson <mwh@python.net>2005-12-05 00:27:49 (GMT)
commitb78a5fc00446c6bfcbbb578cbe471f211a93ea87 (patch)
tree1e3eb720ffb884073b2bc0d1c56e04751f657855 /Objects
parentd54a0aed8e1b67ad1556e4b769fad6def4207f44 (diff)
downloadcpython-b78a5fc00446c6bfcbbb578cbe471f211a93ea87.zip
cpython-b78a5fc00446c6bfcbbb578cbe471f211a93ea87.tar.gz
cpython-b78a5fc00446c6bfcbbb578cbe471f211a93ea87.tar.bz2
Fix bug
[ 1346144 ] Segfaults from unaligned loads in floatobject.c by using memcpy and not just blinding casting char* to double*. Thanks to Rune Holm for the report.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d02e053..b3f861f 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1631,20 +1631,24 @@ _PyFloat_Unpack4(const unsigned char *p, int le)
return x;
}
else {
+ float x;
+
if ((float_format == ieee_little_endian_format && !le)
|| (float_format == ieee_big_endian_format && le)) {
- char buf[8];
+ char buf[4];
char *d = &buf[3];
int i;
for (i = 0; i < 4; i++) {
*d-- = *p++;
}
- return *(float*)&buf[0];
+ memcpy(&x, buf, 4);
}
else {
- return *(float*)p;
+ memcpy(&x, p, 4);
}
+
+ return x;
}
}
@@ -1722,6 +1726,8 @@ _PyFloat_Unpack8(const unsigned char *p, int le)
return x;
}
else {
+ double x;
+
if ((double_format == ieee_little_endian_format && !le)
|| (double_format == ieee_big_endian_format && le)) {
char buf[8];
@@ -1731,10 +1737,12 @@ _PyFloat_Unpack8(const unsigned char *p, int le)
for (i = 0; i < 8; i++) {
*d-- = *p++;
}
- return *(double*)&buf[0];
+ memcpy(&x, buf, 8);
}
else {
- return *(double*)p;
+ memcpy(&x, p, 8);
}
+
+ return x;
}
}