--- ../python/upstream/Python-2.4.1/Python/mystrtoul.c 2003-11-19 08:24:47.000000000 -0700 +++ Python/mystrtoul.c 2005-10-22 10:34:01.000000000 -0600 @@ -39,7 +39,7 @@ { register unsigned long result; /* return value of the function */ register int c; /* current input character */ - register unsigned long temp; /* used in overflow testing */ + register unsigned long smallmax; /* used in overflow checking */ int ovf; /* true if overflow occurred */ result = 0; @@ -83,6 +83,7 @@ } /* do the conversion */ + smallmax = ULONG_MAX / base; while ((c = Py_CHARMASK(*str)) != '\0') { if (isdigit(c) && c - '0' < base) @@ -98,16 +99,12 @@ if (c >= base) /* non-"digit" character */ break; } - temp = result; - result = result * base + c; - if(base == 10) { - if(((long)(result - c) / base != (long)temp)) /* overflow */ - ovf = 1; - } - else { - if ((result - c) / base != temp) /* overflow */ - ovf = 1; - } + if (result > smallmax) + ovf = 1; /* overflow just from shifting */ + result *= base; + if (result + c < result) + ovf = 1; /* overflow from the digit's value */ + result += c; str++; }