Skip to content

Argument Clinic leaves optional string lengths uninitialized #162098

Open

Description

@samitistfobos-dev

Bug report

Argument Clinic leaves the generated length variable uninitialized when an optional s# argument is omitted.

On a --with-pydebug build of CPython main (<commit SHA>), this command segfaults:

./python -c "import _testclinic; print(_testclinic.str_converter())"

Expected output: ('a', 'b', 'c').

In Modules/clinic/_testclinic.c.h, the generated wrapper initializes c to "c" and declares Py_ssize_t c_length; without an initializer. When c is omitted, the parser writes neither variable; for c the C initializer covers it. The wrapper then passes the uninitialized length to str_converter_impl(), which uses it in PyUnicode_FromStringAndSize().

Argument Clinic should initialize the length alongside the pointer default. For this wrapper, the generated declaration should be Py_ssize_t c_length = 1;.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions