[Python-checkins] r71334 - python/branches/py3k-short-float-repr/Python/pystrtod.c

eric.smith python-checkins at python.org
Tue Apr 7 00:49:20 CEST 2009


Author: eric.smith
Date: Tue Apr  7 00:49:20 2009
New Revision: 71334

Log:
Handle out of memory errors from _Py_dg_dtoa.

Modified:
   python/branches/py3k-short-float-repr/Python/pystrtod.c

Modified: python/branches/py3k-short-float-repr/Python/pystrtod.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/pystrtod.c	(original)
+++ python/branches/py3k-short-float-repr/Python/pystrtod.c	Tue Apr  7 00:49:20 2009
@@ -558,6 +558,11 @@
 	/* _Py_dg_dtoa returns a digit string (no decimal point or
 	   exponent).  Must be matched by a call to _Py_dg_freedtoa. */
 	digits = _Py_dg_dtoa(d, mode, precision, &decpt, &sign, &digits_end);
+	if (digits == NULL) {
+		/* The only failure mode is no memory. */
+		PyErr_NoMemory();
+		goto exit;
+	}
 	assert(digits_end != NULL && digits_end >= digits);
 	n_digits = digits_end - digits;
 
@@ -743,7 +748,8 @@
 		   memory that isn't ours. But it's an okay debugging test. */
 		assert(p-buf < bufsize);
 	}
-	_Py_dg_freedtoa(digits);
+	if (digits)
+		_Py_dg_freedtoa(digits);
 
 	return buf;
 }


More information about the Python-checkins mailing list