summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-03-06 21:49:02 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-03-06 21:49:02 (GMT)
commit2db74c2412a785a3b796074f54a7842b8f8f3b9d (patch)
tree097eaf88940add7715bf801700a1a1494a5f8006 /Modules
parent54d0df69c0a57b5d5447f483494293354656c4fa (diff)
downloadcpython-2db74c2412a785a3b796074f54a7842b8f8f3b9d.zip
cpython-2db74c2412a785a3b796074f54a7842b8f8f3b9d.tar.gz
cpython-2db74c2412a785a3b796074f54a7842b8f8f3b9d.tar.bz2
Issue #5429: unaligned access in TextIOWrapper cookie parsing (segfaults on SPARC CPUs, and possibly others)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_textio.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/Modules/_textio.c b/Modules/_textio.c
index 54bf055..145f8ea 100644
--- a/Modules/_textio.c
+++ b/Modules/_textio.c
@@ -1736,11 +1736,11 @@ TextIOWrapper_parseCookie(CookieStruct *cookie, PyObject *cookieObj)
}
Py_DECREF(cookieLong);
- cookie->start_pos = * (Py_off_t *)(buffer + OFF_START_POS);
- cookie->dec_flags = * (int *) (buffer + OFF_DEC_FLAGS);
- cookie->bytes_to_feed = * (int *) (buffer + OFF_BYTES_TO_FEED);
- cookie->chars_to_skip = * (int *) (buffer + OFF_CHARS_TO_SKIP);
- cookie->need_eof = * (char *) (buffer + OFF_NEED_EOF);
+ memcpy(&cookie->start_pos, buffer + OFF_START_POS, sizeof(cookie->start_pos));
+ memcpy(&cookie->dec_flags, buffer + OFF_DEC_FLAGS, sizeof(cookie->dec_flags));
+ memcpy(&cookie->bytes_to_feed, buffer + OFF_BYTES_TO_FEED, sizeof(cookie->bytes_to_feed));
+ memcpy(&cookie->chars_to_skip, buffer + OFF_CHARS_TO_SKIP, sizeof(cookie->chars_to_skip));
+ memcpy(&cookie->need_eof, buffer + OFF_NEED_EOF, sizeof(cookie->need_eof));
return 0;
}
@@ -1750,11 +1750,11 @@ TextIOWrapper_buildCookie(CookieStruct *cookie)
{
unsigned char buffer[COOKIE_BUF_LEN];
- * (Py_off_t *)(buffer + OFF_START_POS) = cookie->start_pos;
- * (int *) (buffer + OFF_DEC_FLAGS) = cookie->dec_flags;
- * (int *) (buffer + OFF_BYTES_TO_FEED) = cookie->bytes_to_feed;
- * (int *) (buffer + OFF_CHARS_TO_SKIP) = cookie->chars_to_skip;
- * (char *) (buffer + OFF_NEED_EOF) = cookie->need_eof;
+ memcpy(buffer + OFF_START_POS, &cookie->start_pos, sizeof(cookie->start_pos));
+ memcpy(buffer + OFF_DEC_FLAGS, &cookie->dec_flags, sizeof(cookie->dec_flags));
+ memcpy(buffer + OFF_BYTES_TO_FEED, &cookie->bytes_to_feed, sizeof(cookie->bytes_to_feed));
+ memcpy(buffer + OFF_CHARS_TO_SKIP, &cookie->chars_to_skip, sizeof(cookie->chars_to_skip));
+ memcpy(buffer + OFF_NEED_EOF, &cookie->need_eof, sizeof(cookie->need_eof));
return _PyLong_FromByteArray(buffer, sizeof(buffer), IS_LITTLE_ENDIAN, 0);
}