Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05bd787

Browse files
committed
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.
1 parent a30eacf commit 05bd787

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

Python/exceptions.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -810,21 +810,21 @@ SyntaxError__str__(PyObject *self, PyObject *args)
810810
if (have_filename)
811811
bufsize += PyString_GET_SIZE(filename);
812812

813-
buffer = PyMem_Malloc(bufsize);
813+
buffer = PyMem_MALLOC(bufsize);
814814
if (buffer != NULL) {
815815
if (have_filename && have_lineno)
816-
sprintf(buffer, "%s (%s, line %ld)",
817-
PyString_AS_STRING(str),
818-
my_basename(PyString_AS_STRING(filename)),
819-
PyInt_AsLong(lineno));
816+
PyOS_snprintf(buffer, bufsize, "%s (%s, line %ld)",
817+
PyString_AS_STRING(str),
818+
my_basename(PyString_AS_STRING(filename)),
819+
PyInt_AsLong(lineno));
820820
else if (have_filename)
821-
sprintf(buffer, "%s (%s)",
822-
PyString_AS_STRING(str),
823-
my_basename(PyString_AS_STRING(filename)));
821+
PyOS_snprintf(buffer, bufsize, "%s (%s)",
822+
PyString_AS_STRING(str),
823+
my_basename(PyString_AS_STRING(filename)));
824824
else if (have_lineno)
825-
sprintf(buffer, "%s (line %ld)",
826-
PyString_AS_STRING(str),
827-
PyInt_AsLong(lineno));
825+
PyOS_snprintf(buffer, bufsize, "%s (line %ld)",
826+
PyString_AS_STRING(str),
827+
PyInt_AsLong(lineno));
828828

829829
result = PyString_FromString(buffer);
830830
PyMem_FREE(buffer);

0 commit comments

Comments
 (0)