Mailing List Archive

python/dist/src/Modules binascii.c,2.34,2.35
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv5769/python/Modules

Modified Files:
binascii.c
Log Message:
Fix for SF bug #576327: zipfile when sizeof(long) == 8
binascii_crc32(): Make this return a signed 4-byte result across
platforms. The other way to make this platform-independent would be to
make it return an unsigned unbounded int, but the evidence suggests
other code out there treats it like a signed 4-byte int (e.g., existing
code writing the result with struct.pack "l" format).

Bugfix candidate.


Index: binascii.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/binascii.c,v
retrieving revision 2.34
retrieving revision 2.35
diff -C2 -d -r2.34 -r2.35
*** binascii.c 13 Jun 2002 20:32:48 -0000 2.34
--- binascii.c 2 Jul 2002 20:20:08 -0000 2.35
***************
*** 865,868 ****
--- 865,869 ----
unsigned long crc = 0UL; /* initial value of CRC */
int len;
+ long result;

if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
***************
*** 873,877 ****
crc = crc_32_tab[(crc ^ *bin_data++) & 0xffUL] ^ (crc >> 8);
/* Note: (crc >> 8) MUST zero fill on left */
! return Py_BuildValue("l", crc ^ 0xFFFFFFFFUL);
}

--- 874,887 ----
crc = crc_32_tab[(crc ^ *bin_data++) & 0xffUL] ^ (crc >> 8);
/* Note: (crc >> 8) MUST zero fill on left */
!
! result = (long)(crc ^ 0xFFFFFFFFUL);
! /* If long is > 32 bits, extend the sign bit. This is one way to
! * ensure the result is the same across platforms. The other way
! * would be to return an unbounded long, but the evidence suggests
! * that lots of code outside this treats the result as if it were
! * a signed 4-byte integer.
! */
! result |= -(result & (1L << 31));
! return PyInt_FromLong(result);
}