Calculate smallest properly (it was off by one) and use proper ssize_t types for Win64

This commit is contained in:
Neal Norwitz 2006-05-31 07:43:27 +00:00
parent 14a0952a1f
commit 971ea11e4c
1 changed files with 5 additions and 5 deletions

View File

@ -309,24 +309,24 @@ static int
_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);
}