Issue #10833: Use PyErr_Format() and PyUnicode_FromFormat() instead of

PyOS_snprintf() to avoid temporary buffer allocated on the stack and a
conversion from bytes to Unicode.
This commit is contained in:
Victor Stinner 2011-03-21 18:15:42 +01:00
parent 44afe2b35a
commit 6ced7c4333
6 changed files with 36 additions and 65 deletions

View file

@ -22,14 +22,7 @@ static PyObject *TestError; /* set to exception object in init */
static PyObject *
raiseTestError(const char* test_name, const char* msg)
{
char buf[2048];
if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
PyErr_SetString(TestError, "internal error msg too large");
else {
PyOS_snprintf(buf, sizeof(buf), "%s: %s", test_name, msg);
PyErr_SetString(TestError, buf);
}
PyErr_Format(TestError, "%s: %s", test_name, msg);
return NULL;
}