From: Guido van Rossum Date: Mon, 29 Jun 1998 04:00:40 +0000 (+0000) Subject: Unsigned 1 and 2 byte sized formats shouldn't result in long integer values! X-Git-Tag: v1.5.2a1~393 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39ef2274a39cbae96b1335969f84da9a9adadc27;p=python Unsigned 1 and 2 byte sized formats shouldn't result in long integer values! --- diff --git a/Modules/structmodule.c b/Modules/structmodule.c index d837e02dc0..af8f1e53c0 100644 --- a/Modules/structmodule.c +++ b/Modules/structmodule.c @@ -694,7 +694,10 @@ bu_uint(p, f) do { x = (x<<8) | (*p++ & 0xFF); } while (--i > 0); - return PyLong_FromUnsignedLong(x); + if (f->size >= 4) + return PyLong_FromUnsignedLong(x); + else + return PyInt_FromLong((long)x); } static PyObject * @@ -825,7 +828,10 @@ lu_uint(p, f) do { x = (x<<8) | (p[--i] & 0xFF); } while (i > 0); - return PyLong_FromUnsignedLong(x); + if (f->size >= 4) + return PyLong_FromUnsignedLong(x); + else + return PyInt_FromLong((long)x); } static PyObject *