[Python-checkins] cpython (merge 3.4 -> default): merge 3.4
benjamin.peterson
python-checkins at python.org
Mon Mar 31 01:54:11 CEST 2014
http://hg.python.org/cpython/rev/cb66598b0bfb
changeset: 90060:cb66598b0bfb
parent: 90053:c830436b25dc
parent: 90059:bd513e5a5047
user: Benjamin Peterson <benjamin at python.org>
date: Sun Mar 30 19:52:50 2014 -0400
summary:
merge 3.4
files:
Objects/stringlib/transmogrify.h | 38 ++++++++++----------
1 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/Objects/stringlib/transmogrify.h b/Objects/stringlib/transmogrify.h
--- a/Objects/stringlib/transmogrify.h
+++ b/Objects/stringlib/transmogrify.h
@@ -15,7 +15,7 @@
{
const char *e, *p;
char *q;
- size_t i, j;
+ Py_ssize_t i, j;
PyObject *u;
static char *kwlist[] = {"tabsize", 0};
int tabsize = 8;
@@ -27,34 +27,30 @@
/* First pass: determine size of output string */
i = j = 0;
e = STRINGLIB_STR(self) + STRINGLIB_LEN(self);
- for (p = STRINGLIB_STR(self); p < e; p++)
+ for (p = STRINGLIB_STR(self); p < e; p++) {
if (*p == '\t') {
if (tabsize > 0) {
- j += tabsize - (j % tabsize);
- if (j > PY_SSIZE_T_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "result is too long");
- return NULL;
- }
+ Py_ssize_t incr = tabsize - (j % tabsize);
+ if (j > PY_SSIZE_T_MAX - incr)
+ goto overflow;
+ j += incr;
}
}
else {
+ if (j > PY_SSIZE_T_MAX - 1)
+ goto overflow;
j++;
if (*p == '\n' || *p == '\r') {
+ if (i > PY_SSIZE_T_MAX - j)
+ goto overflow;
i += j;
j = 0;
- if (i > PY_SSIZE_T_MAX) {
- PyErr_SetString(PyExc_OverflowError,
- "result is too long");
- return NULL;
- }
}
}
+ }
- if ((i + j) > PY_SSIZE_T_MAX) {
- PyErr_SetString(PyExc_OverflowError, "result is too long");
- return NULL;
- }
+ if (i > PY_SSIZE_T_MAX - j)
+ goto overflow;
/* Second pass: create output string and fill it */
u = STRINGLIB_NEW(NULL, i + j);
@@ -63,8 +59,8 @@
j = 0;
q = STRINGLIB_STR(u);
-
- for (p = STRINGLIB_STR(self); p < e; p++)
+
+ for (p = STRINGLIB_STR(self); p < e; p++) {
if (*p == '\t') {
if (tabsize > 0) {
i = tabsize - (j % tabsize);
@@ -79,8 +75,12 @@
if (*p == '\n' || *p == '\r')
j = 0;
}
+ }
return u;
+ overflow:
+ PyErr_SetString(PyExc_OverflowError, "result too long");
+ return NULL;
}
Py_LOCAL_INLINE(PyObject *)
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list