Skip to content

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

Closed

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

  1. added
    bug
    core-engine
    testing
    on Aug 19, 2026
  2. squid-protocol commented on Aug 28, 2026

    @squid-protocol
    OwnerAuthor

    Fixed in #1884 (merged). _count_top_level_args now detects the function-pointer-return shape (void (*foo(int a, int b))(int c), incl. the pointer-to-member form) and re-slices to the correct inner (. Verified: all three repro signatures now return 2. Regression tests test_count_top_level_args_function_pointer_return_type_1854 and test_count_top_level_args_function_pointer_edge_cases_1854_review pass on current main.

  3. added this to the v2.4.9 milestone on Aug 31, 2026
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

    bugcore-enginepriority: mediumtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions