diff Objects/moduleobject.c @ 19476:0e70df98424e legacy-trunk

repr's converted to using PyString_FromFormat() instead of sprintf'ing into a hardcoded char* buffer. Closes patch #454743.
author Barry Warsaw <barry@python.org>
date Fri, 24 Aug 2001 18:34:26 +0000
parents 1fec03012346
children fd48a55ac364
line wrap: on
line diff
--- a/Objects/moduleobject.c	Fri Aug 24 18:32:06 2001 +0000
+++ b/Objects/moduleobject.c	Fri Aug 24 18:34:26 2001 +0000
@@ -157,13 +157,8 @@
 static PyObject *
 module_repr(PyModuleObject *m)
 {
-	static int template1len = sizeof("<module '' (built-in)>") + 1;
-	static int template2len = sizeof("<module '' from ''>") + 1;
-
-	char *buf;
 	char *name;
 	char *filename;
-	PyObject *rtn;
 
 	name = PyModule_GetName((PyObject *)m);
 	if (name == NULL) {
@@ -173,19 +168,9 @@
 	filename = PyModule_GetFilename((PyObject *)m);
 	if (filename == NULL) {
 		PyErr_Clear();
-		buf = PyObject_MALLOC(
-			sizeof(char) * (strlen(name) + template1len));
-		sprintf(buf, "<module '%s' (built-in)>", name);
+		return PyString_FromFormat("<module '%s' (built-in)>", name);
 	}
-	else {
-		buf = PyObject_MALLOC(
-			sizeof(char) * (strlen(name) + strlen(filename) +
-					template2len));
-		sprintf(buf, "<module '%s' from '%s'>", name, filename);
-	}
-	rtn = PyString_FromString(buf);
-	PyObject_FREE(buf);
-	return rtn;
+	return PyString_FromFormat("<module '%s' from '%s'>", name, filename);
 }
 
 /* We only need a traverse function, no clear function: If the module