diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index b65887e2eca1b1..e39e398b85151f 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -953,6 +953,15 @@ Generally you only use this feature if you receive a pointer from a C function, and you *know* that the pointer actually points to an array instead of a single item. +.. warning:: + + Because pointer objects support subscription, they implicitly support + :term:`iteration `. Unless doing this in a controlled manner, + such as by manually calling :func:`next` on a :func:`pointer` iterator, this + will typically lead to infinite loops or crashes, because ctypes has no way + of knowing when to stop iteration. In other words, a ``pointer`` iterator + will infinitely yield arbitrary memory. + Behind the scenes, the :func:`pointer` function does more than simply create pointer instances, it has to create pointer *types* first. This is done with the :func:`POINTER` function, which accepts any :mod:`!ctypes` type, and returns a