Kaydet (Commit) b569ee48 authored tarafından Georg Brandl's avatar Georg Brandl

Handle PyMem_Malloc failure in pystrtod.c. Closes #1494671.

üst a1121fa9
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
* is returned (according to the sign of the value), and %ERANGE is * is returned (according to the sign of the value), and %ERANGE is
* stored in %errno. If the correct value would cause underflow, * stored in %errno. If the correct value would cause underflow,
* zero is returned and %ERANGE is stored in %errno. * 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 * This function resets %errno before calling strtod() so that
* you can reliably detect overflow and underflow. * you can reliably detect overflow and underflow.
...@@ -102,6 +103,12 @@ PyOS_ascii_strtod(const char *nptr, char **endptr) ...@@ -102,6 +103,12 @@ PyOS_ascii_strtod(const char *nptr, char **endptr)
/* We need to convert the '.' to the locale specific decimal point */ /* We need to convert the '.' to the locale specific decimal point */
copy = (char *)PyMem_MALLOC(end - nptr + 1 + decimal_point_len); copy = (char *)PyMem_MALLOC(end - nptr + 1 + decimal_point_len);
if (copy == NULL) {
if (endptr)
*endptr = nptr;
errno = ENOMEM;
return val;
}
c = copy; c = copy;
memcpy(c, nptr, decimal_point_pos - nptr); memcpy(c, nptr, decimal_point_pos - nptr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment