Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives in functions that returns a struct #8

Closed
pellenilsson opened this issue Aug 25, 2017 · 4 comments
Closed

False positives in functions that returns a struct #8

pellenilsson opened this issue Aug 25, 2017 · 4 comments

Comments

@pellenilsson
Copy link

I experience many false positives in all functions that return a struct or a pointer to struct. Here is a very simple example.

filefilter.txt:

~ RULE_6_1_A_do_not_omit_function_parameter_names

nsiq_test.c:

struct test_struct
{
    int a;
    int b;
};

void func1(int *p, int x);

struct test_struct func2(void)
{
    struct test_struct ts = {1, 2};
    return ts;

    func1(NULL, 0);
}

This gives the following false positive:

/home/pnin/src/skunk/nsiq_test.c(14, 5):  function (func1) has non named parameter. use named parameter.  [RULE_6_1_A_do_not_omit_function_parameter_names]

If I change the return type of func2 to int instead of struct test_struct the error goes away. I suspect that func2 is treated as a struct instead of a function. If I dump contextStack during each iteration in nsiqcppstyle_checker.py, I get this when func2 returns an int:

FUNCTION_BLOCK, func2, LexToken(LBRACE,'{',10,1,91, False, None), LexToken(RBRACE,'}',15,1,165, False, None) >>

And this when func2 returns a struct:

STRUCT_BLOCK, func2, LexToken(LBRACE,'{',10,1,106, False, None), LexToken(RBRACE,'}',15,1,180, False, None) >>
@kunaltyagi
Copy link
Owner

This is because this code isn't built for C language. If you want to use it for C, use the typedef strict in order to prevent the lexer from thinking it is a struct instead of a function.
Thanks for the detailed context, and the minimal example.
Close the issue if it helps.
Cheers

@pellenilsson
Copy link
Author

The README (and the original description on Google Code) claims that both C and C++ are supported, so it would be nice if the documentation explained what limitations exist for C code.

@kunaltyagi
Copy link
Owner

I have no control over Google Code since I am not the original author, but am maintaining the code for personal use.
However, I'll try to work on this issue. I'll update the README here to incorporate this limitation.
If you can figure out a way to remove the corner case, do create a PR

kunaltyagi added a commit that referenced this issue Sep 21, 2017
@pellenilsson
Copy link
Author

Thanks! I'll keep you updated in case I find time to do something about it.

Closing the bug since it's now a documented feature. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants