From 300b54522d292c96cb2ff0f67fcf89f0c34a4677 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 aeab25675..21d10eb7d 100644 --- a/_imaging.c +++ b/_imaging.c @@ -1294,14 +1294,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++;