]> granicus.if.org Git - python/commitdiff
Removed usage of unsafe PyFloat_AsString.
authorEric Smith <eric@trueblade.com>
Fri, 16 Oct 2009 14:26:36 +0000 (14:26 +0000)
committerEric Smith <eric@trueblade.com>
Fri, 16 Oct 2009 14:26:36 +0000 (14:26 +0000)
Objects/floatobject.c

index 73d6a1ff417e511811030a474bfcecdafd88396e..745fe542265f86144d63680808f25e3473b1a093 100644 (file)
@@ -2012,15 +2012,21 @@ PyFloat_Fini(void)
                             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;