py3k: Fix strict aliasing slip-up in _imaging

Python 3 enables C's strict aliasing rules for the first time, which means
you need to be careful about the ways you reference pointers. Here, we're
using a char[4] as an INT32, so we cast between them using a union.
This commit is contained in:
Brian Crowell 2012-10-13 22:24:48 -05:00 committed by Brian Crowell
parent d28a2fee76
commit 89e82c5888

View File

@ -1308,14 +1308,18 @@ _putdata(ImagingObject* self, PyObject* args)
break;
default:
for (i = x = y = 0; i < n; i++) {
char ink[4];
union {
char ink[4];
INT32 inkint;
} u;
PyObject *op = PySequence_GetItem(data, i);
if (!op || !getink(op, image, ink)) {
if (!op || !getink(op, image, u.ink)) {
Py_DECREF(op);
return NULL;
}
/* FIXME: what about scale and offset? */
image->image32[y][x] = *((INT32*) ink);
image->image32[y][x] = u.inkint;
Py_XDECREF(op);
if (++x >= (int) image->xsize)
x = 0, y++;