always check _PyString_Resize for error

also normalize how this error is checked
This commit is contained in:
Benjamin Peterson 2010-04-02 23:59:41 +00:00
parent 4564c08b26
commit 6caf7ff505
1 changed files with 12 additions and 10 deletions

View File

@ -395,7 +395,8 @@ PyString_FromFormatV(const char *format, va_list vargs)
} }
end: end:
_PyString_Resize(&string, s - PyString_AS_STRING(string)); if (_PyString_Resize(&string, s - PyString_AS_STRING(string)))
return NULL;
return string; return string;
} }
@ -747,8 +748,8 @@ PyObject *PyString_DecodeEscape(const char *s,
UTF-8 bytes may follow. */ UTF-8 bytes may follow. */
} }
} }
if (p-buf < newlen) if (p-buf < newlen && _PyString_Resize(&v, p - buf))
_PyString_Resize(&v, p - buf); goto failed;
return v; return v;
failed: failed:
Py_DECREF(v); Py_DECREF(v);
@ -977,8 +978,8 @@ PyString_Repr(PyObject *obj, int smartquotes)
assert(newsize - (p - PyString_AS_STRING(v)) >= 1); assert(newsize - (p - PyString_AS_STRING(v)) >= 1);
*p++ = quote; *p++ = quote;
*p = '\0'; *p = '\0';
_PyString_Resize( if (_PyString_Resize(&v, (p - PyString_AS_STRING(v))))
&v, (p - PyString_AS_STRING(v))); return NULL;
return v; return v;
} }
} }
@ -2301,8 +2302,8 @@ string_translate(PyStringObject *self, PyObject *args)
return input_obj; return input_obj;
} }
/* Fix the size of the resulting string */ /* Fix the size of the resulting string */
if (inlen > 0) if (inlen > 0 && _PyString_Resize(&result, output - output_start))
_PyString_Resize(&result, output - output_start); return NULL;
return result; return result;
} }
@ -4254,7 +4255,7 @@ PyString_Format(PyObject *format, PyObject *args)
if (--rescnt < 0) { if (--rescnt < 0) {
rescnt = fmtcnt + 100; rescnt = fmtcnt + 100;
reslen += rescnt; reslen += rescnt;
if (_PyString_Resize(&result, reslen) < 0) if (_PyString_Resize(&result, reslen))
return NULL; return NULL;
res = PyString_AS_STRING(result) res = PyString_AS_STRING(result)
+ reslen - rescnt; + reslen - rescnt;
@ -4581,7 +4582,7 @@ PyString_Format(PyObject *format, PyObject *args)
Py_XDECREF(temp); Py_XDECREF(temp);
return PyErr_NoMemory(); return PyErr_NoMemory();
} }
if (_PyString_Resize(&result, reslen) < 0) { if (_PyString_Resize(&result, reslen)) {
Py_XDECREF(temp); Py_XDECREF(temp);
return NULL; return NULL;
} }
@ -4649,7 +4650,8 @@ PyString_Format(PyObject *format, PyObject *args)
if (args_owned) { if (args_owned) {
Py_DECREF(args); Py_DECREF(args);
} }
_PyString_Resize(&result, reslen - rescnt); if (_PyString_Resize(&result, reslen - rescnt))
return NULL;
return result; return result;
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE