Skip to content

Missing error / null pointer checks in Parser/action_helpers.c #149689

@KowalskiThomas

Description

@KowalskiThomas

I'm opening this issue to discuss something I've noticed in Parser/action_helpers.c. There are multiple places where functions are called and their result is not checked, meaning if they error, Python will continue to try and execute its logic even though it would only be reasonable to bail. I initially thought those call sites skipped the return code / null pointer checks because they were redundant (i.e. that there was some assumption that some function calls can never fail) but upon further scrutiny that seems to be the case for none of them.


To take one random example:

  • _set_seq_context does asdl_seq_SET(new_seq, i, _PyPegen_set_expr_context(p, e, ctx)); here
  • _PyPegen_set_expr_context calls one of many functions, e.g. _set_name_context here
  • _set_name_context calls into _PyAST_Name
  • ... which may return NULL in several cases

The other cases are similar.


I have a fix branch here which also serves as a list of all the places in this specific file that would be worth fixing.

Let me know what you think.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-parsertriagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions