diff -r f97630b6ebd8 Objects/stringlib/transmogrify.h --- a/Objects/stringlib/transmogrify.h Tue Jan 13 03:11:23 2009 +0100 +++ b/Objects/stringlib/transmogrify.h Tue Jan 13 20:56:20 2009 +0100 @@ -22,7 +22,7 @@ stringlib_expandtabs(PyObject *self, PyO { const char *e, *p; char *q; - Py_ssize_t i, j, old_j; + size_t i, j, old_i, old_j; PyObject *u; int tabsize = 8; @@ -30,15 +30,13 @@ stringlib_expandtabs(PyObject *self, PyO return NULL; /* First pass: determine size of output string */ - i = j = old_j = 0; + i = j = old_i = old_j = 0; e = STRINGLIB_STR(self) + STRINGLIB_LEN(self); for (p = STRINGLIB_STR(self); p < e; p++) if (*p == '\t') { if (tabsize > 0) { j += tabsize - (j % tabsize); - /* XXX: this depends on a signed integer overflow to < 0 */ - /* C compilers, including gcc, do -NOT- guarantee this. */ - if (old_j > j) { + if (j > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "result is too long"); return NULL; @@ -51,19 +49,16 @@ stringlib_expandtabs(PyObject *self, PyO if (*p == '\n' || *p == '\r') { i += j; old_j = j = 0; - /* XXX: this depends on a signed integer overflow to < 0 */ - /* C compilers, including gcc, do -NOT- guarantee this. */ - if (i < 0) { + if (i > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "result is too long"); return NULL; } + old_i = i; } } - if ((i + j) < 0) { - /* XXX: this depends on a signed integer overflow to < 0 */ - /* C compilers, including gcc, do -NOT- guarantee this. */ + if ((i + j) > PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "result is too long"); return NULL; }