From 30333de036b9e044bc9b185caa8f2f50023aeecb Mon Sep 17 00:00:00 2001 From: Brian Crowell Date: Sat, 13 Oct 2012 22:24:48 -0500 Subject: [PATCH] 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. --- _imaging.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/_imaging.c b/_imaging.c index f599e124e..355f0f86a 100644 --- a/_imaging.c +++ b/_imaging.c @@ -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++;