Skip to content

complex_abs() should call _Py_c_abs() with errno=0 set #155526

Description

@skirpichev

Bug report

Bug description:

Other _Py_* helpers in the complexobject.c - only set errno on errors, assuming that it was set to 0 prior to the function call. This is not the case for _Py_c_abs().

So, it's possible to trigger OverflowError in abs() for nan's input:

$ cat a.py
import _testcapi
z = complex('nan')
_testcapi.set_errno(34)
abs(z)
$ ./python a.py 
Traceback (most recent call last):
  File "/home/sk/src/cpython/a.py", line 4, in <module>
    abs(z)
    ~~~^^^
OverflowError: absolute value too large

Credits for @devdanzin for discovery.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions