]> granicus.if.org Git - python/commitdiff
Unsigned 1 and 2 byte sized formats shouldn't result in long integer values!
authorGuido van Rossum <guido@python.org>
Mon, 29 Jun 1998 04:00:40 +0000 (04:00 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 29 Jun 1998 04:00:40 +0000 (04:00 +0000)
Modules/structmodule.c

index d837e02dc0a550bb2f4a0d4550ceb9fd2561c0df..af8f1e53c064ba3b9e718461f98d64450d2e1256 100644 (file)
@@ -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 *