Skip to content

Commit b327258

Browse files
committed
Removed usage of unsafe PyFloat_AsString.
1 parent 03d5c34 commit b327258

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎Objects/floatobject.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,15 +2012,21 @@ PyFloat_Fini(void)
20122012
i++, p++) {
20132013
if (PyFloat_CheckExact(p) &&
20142014
Py_REFCNT(p) != 0) {
2015-
char buf[100];
2016-
PyFloat_AsString(buf, p);
2017-
/* XXX(twouters) cast refcount to
2018-
long until %zd is universally
2019-
available
2020-
*/
2021-
fprintf(stderr,
2015+
char *buf = PyOS_double_to_string(
2016+
PyFloat_AS_DOUBLE(p), 'r',
2017+
0, 0, NULL);
2018+
if (buf) {
2019+
/* XXX(twouters) cast
2020+
refcount to long
2021+
until %zd is
2022+
universally
2023+
available
2024+
*/
2025+
fprintf(stderr,
20222026
"# <float at %p, refcnt=%ld, val=%s>\n",
20232027
p, (long)Py_REFCNT(p), buf);
2028+
PyMem_Free(buf);
2029+
}
20242030
}
20252031
}
20262032
list = list->next;

0 commit comments

Comments
 (0)