[Python-checkins] commit of r41601 - python/trunk/Objects/floatobject.c
michael.hudson
python-checkins at python.org
Mon Dec 5 01:27:55 CET 2005
Author: michael.hudson
Date: Mon Dec 5 01:27:49 2005
New Revision: 41601
Modified:
python/trunk/Objects/floatobject.c
Log:
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.
Modified: python/trunk/Objects/floatobject.c
==============================================================================
--- python/trunk/Objects/floatobject.c (original)
+++ python/trunk/Objects/floatobject.c Mon Dec 5 01:27:49 2005
@@ -1631,20 +1631,24 @@
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 @@
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 @@
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;
}
}
More information about the Python-checkins
mailing list