Skip to content

Add NULL checks after PyTuple_Pack calls to prevent potential errors #128

@sourcery-ai

Description

@sourcery-ai

The codebase currently lacks NULL checks after calls to PyTuple_Pack, which can return NULL on error. This issue poses a bug risk as it can lead to unexpected behavior or crashes if the error is not handled properly.

The specific instance mentioned is in the code where PyTuple_Pack is used without checking for a NULL return value. The suggested fix is to add a NULL check immediately after the PyTuple_Pack call, as follows:

PyObject *tuple = PyTuple_Pack(2, path, retval);
if (tuple == NULL) {
    return NULL;
}

Additionally, there are other files such as kvitems_basecoro.c and parse_basecoro.c that also lack these checks. It is recommended to perform a comprehensive review and update all instances where PyTuple_Pack is used without a NULL check across the codebase. A separate commit addressing all these instances would be beneficial to ensure consistency and robustness in error handling.


I created this issue for @wodny from #127 (comment).

Tips and commands

Interacting with Sourcery

  • Generate a plan of action: Comment @sourcery-ai plan on this issue.
  • Generate a pull request for this issue: Comment @sourcery-ai develop to
    generate a PR that addresses this issue.

Getting Help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions