summaryrefslogtreecommitdiff
path: root/Python/pystrtod.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-05-29 14:28:05 +0000
committerGeorg Brandl <georg@python.org>2006-05-29 14:28:05 +0000
commitbd34cf3d05d90f4d0e049cff973a56623e5df308 (patch)
treea4b16524e4d11f11afa663f685440e2c4a5c8193 /Python/pystrtod.c
parenta70d59eed5b2e1f69efa48e211f0cd94faba7f85 (diff)
downloadcpython-bd34cf3d05d90f4d0e049cff973a56623e5df308.tar.gz
Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.
Diffstat (limited to 'Python/pystrtod.c')
-rw-r--r--Python/pystrtod.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 8a71c285a9..53d6325f89 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -31,6 +31,7 @@
* is returned (according to the sign of the value), and %ERANGE is
* stored in %errno. If the correct value would cause underflow,
* zero is returned and %ERANGE is stored in %errno.
+ * If memory allocation fails, %ENOMEM is stored in %errno.
*
* This function resets %errno before calling strtod() so that
* you can reliably detect overflow and underflow.
@@ -102,6 +103,12 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
/* We need to convert the '.' to the locale specific decimal point */
copy = (char *)PyMem_MALLOC(end - nptr + 1 + decimal_point_len);
+ if (copy == NULL) {
+ if (endptr)
+ *endptr = nptr;
+ errno = ENOMEM;
+ return val;
+ }
c = copy;
memcpy(c, nptr, decimal_point_pos - nptr);