mirror of
https://github.com/python/cpython.git
synced 2026-10-28 10:25:05 +08:00
gh-159739: Propagate float rounding allocation failures (#160195)
This commit is contained in:
1 parent
cc36604f7b
commit
3e7393bdf5
2 files changed
+8
-2
No files matched your search
@@ -0,0 +1 @@
|
||||
Raise :exc:`MemoryError` instead of returning an incorrect result if :func:`round` runs out of memory while rounding a float.
|
||||
@@ -942,11 +942,16 @@ double_round(double x, int ndigits) {
|
||||
_Py_SET_53BIT_PRECISION_START;
|
||||
rounded = _Py_dg_strtod(mybuf, NULL);
|
||||
_Py_SET_53BIT_PRECISION_END;
|
||||
if (errno == ERANGE && fabs(rounded) >= 1.)
|
||||
if (errno == ENOMEM) {
|
||||
PyErr_NoMemory();
|
||||
}
|
||||
else if (errno == ERANGE && fabs(rounded) >= 1.) {
|
||||
PyErr_SetString(PyExc_OverflowError,
|
||||
"rounded value too large to represent");
|
||||
else
|
||||
}
|
||||
else {
|
||||
result = PyFloat_FromDouble(rounded);
|
||||
}
|
||||
|
||||
/* done computing value; now clean up */
|
||||
if (mybuf != shortbuf)
|
||||
|
||||
Reference in new issue
Block a user