[Python-checkins] r46572 - python/trunk/Modules/_struct.c

neal.norwitz python-checkins at python.org
Wed May 31 09:43:28 CEST 2006


Author: neal.norwitz
Date: Wed May 31 09:43:27 2006
New Revision: 46572

Modified:
   python/trunk/Modules/_struct.c
Log:
Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64

Modified: python/trunk/Modules/_struct.c
==============================================================================
--- python/trunk/Modules/_struct.c	(original)
+++ python/trunk/Modules/_struct.c	Wed May 31 09:43:27 2006
@@ -309,24 +309,24 @@
 _range_error(const formatdef *f, int is_unsigned)
 {
 	if (is_unsigned == 0) {
-		long smallest = 0, largest = 0;
+		Py_ssize_t smallest, largest = 0;
 		Py_ssize_t i = f->size * 8;
 		while (--i > 0) {
-			smallest = (smallest * 2) - 1;
 			largest = (largest * 2) + 1;
 		}
+		smallest = -largest - 1;
 		PyErr_Format(StructError,
-			"'%c' format requires %ld <= number <= %ld",
+			"'%c' format requires %zd <= number <= %zd",
 			f->format,
 			smallest,
 			largest);
 	} else {
-		unsigned long largest = 0;
+		size_t largest = 0;
 		Py_ssize_t i = f->size * 8;
 		while (--i >= 0)
 			largest = (largest * 2) + 1;
 		PyErr_Format(StructError,
-			"'%c' format requires 0 <= number <= %lu",
+			"'%c' format requires 0 <= number <= %zu",
 			f->format,
 			largest);
 	}


More information about the Python-checkins mailing list