summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2024-12-04 13:13:52 (GMT)
committerGitHub <noreply@github.com>2024-12-04 13:13:52 (GMT)
commitbc0f2e945993747c8b1a6dd66cbe902fddd5758b (patch)
tree289cb0e345924f7ae72a0f6caa5b148d1380b021 /Doc
parentad9d059eb10ef132edd73075fa6d8d96d95b8701 (diff)
downloadcpython-bc0f2e945993747c8b1a6dd66cbe902fddd5758b.zip
cpython-bc0f2e945993747c8b1a6dd66cbe902fddd5758b.tar.gz
cpython-bc0f2e945993747c8b1a6dd66cbe902fddd5758b.tar.bz2
gh-123378: Ensure results of `PyUnicode*Error_Get{Start,End}` are clamped (GH-123380)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/exceptions.rst20
-rw-r--r--Doc/library/exceptions.rst6
2 files changed, 24 insertions, 2 deletions
diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst
index fc2336d..c1f0bd7 100644
--- a/Doc/c-api/exceptions.rst
+++ b/Doc/c-api/exceptions.rst
@@ -853,12 +853,23 @@ The following functions are used to create and modify Unicode exceptions from C.
*\*start*. *start* must not be ``NULL``. Return ``0`` on success, ``-1`` on
failure.
+ If the :attr:`UnicodeError.object` is an empty sequence, the resulting
+ *start* is ``0``. Otherwise, it is clipped to ``[0, len(object) - 1]``.
+
+ .. seealso:: :attr:`UnicodeError.start`
+
.. c:function:: int PyUnicodeDecodeError_SetStart(PyObject *exc, Py_ssize_t start)
int PyUnicodeEncodeError_SetStart(PyObject *exc, Py_ssize_t start)
int PyUnicodeTranslateError_SetStart(PyObject *exc, Py_ssize_t start)
- Set the *start* attribute of the given exception object to *start*. Return
- ``0`` on success, ``-1`` on failure.
+ Set the *start* attribute of the given exception object to *start*.
+ Return ``0`` on success, ``-1`` on failure.
+
+ .. note::
+
+ While passing a negative *start* does not raise an exception,
+ the corresponding getters will not consider it as a relative
+ offset.
.. c:function:: int PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
int PyUnicodeEncodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
@@ -868,6 +879,9 @@ The following functions are used to create and modify Unicode exceptions from C.
*\*end*. *end* must not be ``NULL``. Return ``0`` on success, ``-1`` on
failure.
+ If the :attr:`UnicodeError.object` is an empty sequence, the resulting
+ *end* is ``0``. Otherwise, it is clipped to ``[1, len(object)]``.
+
.. c:function:: int PyUnicodeDecodeError_SetEnd(PyObject *exc, Py_ssize_t end)
int PyUnicodeEncodeError_SetEnd(PyObject *exc, Py_ssize_t end)
int PyUnicodeTranslateError_SetEnd(PyObject *exc, Py_ssize_t end)
@@ -875,6 +889,8 @@ The following functions are used to create and modify Unicode exceptions from C.
Set the *end* attribute of the given exception object to *end*. Return ``0``
on success, ``-1`` on failure.
+ .. seealso:: :attr:`UnicodeError.end`
+
.. c:function:: PyObject* PyUnicodeDecodeError_GetReason(PyObject *exc)
PyObject* PyUnicodeEncodeError_GetReason(PyObject *exc)
PyObject* PyUnicodeTranslateError_GetReason(PyObject *exc)
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index b5ba86f..f72b11e 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -644,10 +644,16 @@ The following exceptions are the exceptions that are usually raised.
The first index of invalid data in :attr:`object`.
+ This value should not be negative as it is interpreted as an
+ absolute offset but this constraint is not enforced at runtime.
+
.. attribute:: end
The index after the last invalid data in :attr:`object`.
+ This value should not be negative as it is interpreted as an
+ absolute offset but this constraint is not enforced at runtime.
+
.. exception:: UnicodeEncodeError