diff Objects/floatobject.c @ 56549:7fa14be8ad73 legacy-trunk

Removed usage of unsafe PyFloat_AsString.
author Eric Smith <eric@trueblade.com>
date Fri, 16 Oct 2009 14:26:36 +0000
parents 4c6cdba1b0bb
children edf35c3a48ab
line wrap: on
line diff
--- a/Objects/floatobject.c	Fri Oct 16 14:06:44 2009 +0000
+++ b/Objects/floatobject.c	Fri Oct 16 14:26:36 2009 +0000
@@ -2012,15 +2012,21 @@
 			     i++, p++) {
 				if (PyFloat_CheckExact(p) &&
 				    Py_REFCNT(p) != 0) {
-					char buf[100];
-					PyFloat_AsString(buf, p);
-					/* XXX(twouters) cast refcount to
-					   long until %zd is universally
-					   available
-					 */
-					fprintf(stderr,
+					char *buf = PyOS_double_to_string(
+						PyFloat_AS_DOUBLE(p), 'r',
+						0, 0, NULL);
+					if (buf) {
+						/* XXX(twouters) cast
+						   refcount to long
+						   until %zd is
+						   universally
+						   available
+						*/
+						fprintf(stderr,
 			     "#   <float at %p, refcnt=%ld, val=%s>\n",
 						p, (long)Py_REFCNT(p), buf);
+						PyMem_Free(buf);
+					}
 				}
 			}
 			list = list->next;