Skip to content

Bug: C/C++ Function Pointer Return Types Misalign Argument Block #1854

Description

@squid-protocol

Bug: C/C++ Function Pointer Return Types Misalign Argument Block

Description

In gitgalaxy/core/detector.py, the _count_top_level_args parses the argument string by assuming the parameter list starts after the first open parenthesis it encounters:

if not treat_as_body:
    open_idx = args_str.find("(")
    if open_idx != -1:
        body = args_str[open_idx + 1 : self._matching_paren_end(args_str, open_idx)]

For standard function signatures (e.g. int foo(int a, int b)), this reliably isolates the parameter block. However, if a C or C++ function returns a function pointer, the function name is wrapped in a parenthesis (e.g., void (*foo(int a, int b))(int c)).

Impact

The .find("(") logic incorrectly locks onto the opening parenthesis of the return type block ((*foo...).
The resulting body string ends up being truncated incorrectly (e.g., *foo(int a, int b), creating an unbalanced open parenthesis. All commas inside this misaligned block are treated as having depth = 1 and are therefore hidden from the argument counter.

Steps to Reproduce

  1. Test with the signature: void (*foo(int a, int b))(int c)
  2. Observe that the returned argument count is 0 instead of 2.

Suggested Fix

Improve the bounding logic for C-family languages to detect function pointer syntax and skip to the correct parameter parenthesis, or use treat_as_body=True for these specific signatures so the regex handles the precise capture.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUnintended behavior or logic failure in the enginecore-engineModifications to the central physics and parsing enginepriority: mediumtestingUnit, integration, and E2E pipeline verification

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions