From: Jeremy Hylton Date: Wed, 28 Nov 2001 20:24:33 +0000 (+0000) Subject: Use PyOS_snprintf instead of sprintf. X-Git-Tag: v2.2.1c1~680 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05bd787c6cd55f29d43465de621778221e0fc46e;p=python Use PyOS_snprintf instead of sprintf. Just being sure. The old code looks like it was safe, but there's no harm in double-checking. --- diff --git a/Python/exceptions.c b/Python/exceptions.c index 4d17529720..99002bf1ad 100644 --- a/Python/exceptions.c +++ b/Python/exceptions.c @@ -810,21 +810,21 @@ SyntaxError__str__(PyObject *self, PyObject *args) if (have_filename) bufsize += PyString_GET_SIZE(filename); - buffer = PyMem_Malloc(bufsize); + buffer = PyMem_MALLOC(bufsize); if (buffer != NULL) { if (have_filename && have_lineno) - sprintf(buffer, "%s (%s, line %ld)", - PyString_AS_STRING(str), - my_basename(PyString_AS_STRING(filename)), - PyInt_AsLong(lineno)); + PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)", + PyString_AS_STRING(str), + my_basename(PyString_AS_STRING(filename)), + PyInt_AsLong(lineno)); else if (have_filename) - sprintf(buffer, "%s (%s)", - PyString_AS_STRING(str), - my_basename(PyString_AS_STRING(filename))); + PyOS_snprintf(buffer, bufsize, "%s (%s)", + PyString_AS_STRING(str), + my_basename(PyString_AS_STRING(filename))); else if (have_lineno) - sprintf(buffer, "%s (line %ld)", - PyString_AS_STRING(str), - PyInt_AsLong(lineno)); + PyOS_snprintf(buffer, bufsize, "%s (line %ld)", + PyString_AS_STRING(str), + PyInt_AsLong(lineno)); result = PyString_FromString(buffer); PyMem_FREE(buffer);