diff options
author | Stefan Krah <skrah@bytereef.org> | 2013-01-24 14:22:33 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2013-01-24 14:22:33 (GMT) |
commit | eb8c451bd27e64356d848c5e0a0d35b9d70371ca (patch) | |
tree | c9fffbdf32871a96d440e376e93844b3a2295e6a /Modules/_decimal | |
parent | 33f7cdd9751b23b4ab5b9419c1209dc30c86fa39 (diff) | |
download | cpython-eb8c451bd27e64356d848c5e0a0d35b9d70371ca.zip cpython-eb8c451bd27e64356d848c5e0a0d35b9d70371ca.tar.gz cpython-eb8c451bd27e64356d848c5e0a0d35b9d70371ca.tar.bz2 |
Since the return type of format() is not a Decimal, raise ValueError instead of
InvalidOperation if the format specification (width, prec) exceeds the internal
limits of libmpdec.
Diffstat (limited to 'Modules/_decimal')
-rw-r--r-- | Modules/_decimal/_decimal.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index 5e9fd67..89386ff 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -3222,7 +3222,13 @@ dec_format(PyObject *dec, PyObject *args) decstring = mpd_qformat_spec(MPD(dec), &spec, CTX(context), &status); if (decstring == NULL) { - dec_addstatus(context, status); + if (status & MPD_Malloc_error) { + PyErr_NoMemory(); + } + else { + PyErr_SetString(PyExc_ValueError, + "format specification exceeds internal limits of _decimal"); + } goto finish; } result = PyUnicode_DecodeUTF8(decstring, strlen(decstring), NULL); |