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

enable misra-c2012-2.7 #1813

Merged
merged 2 commits into from
Jan 17, 2024
Merged

Conversation

0x41head
Copy link
Contributor

for #1794

@0x41head 0x41head marked this pull request as ready for review January 16, 2024 18:54
@0x41head
Copy link
Contributor Author

the 2.7 check seems to be broken:

def misra_2_7(self, data):
        for func in data.functions:
            # Skip function with no parameter
            if len(func.argument) == 0:
                continue
            # Setup list of function parameters
            func_param_list = list()
            for arg in func.argument:
                func_arg = func.argument[arg]
                if func_arg.typeStartToken and func_arg.typeStartToken.str == '...':
                    continue
                func_param_list.append(func_arg)
            # Search for scope of current function
            for scope in data.scopes:
                if (scope.type == "Function") and (scope.function == func):
                    # Search function body: remove referenced function parameter from list
                    token = scope.bodyStart
                    while token.next is not None and token != scope.bodyEnd and len(func_param_list) > 0:
                        if token.variable is not None and token.variable in func_param_list:
                            func_param_list.remove(token.variable)
                        token = token.next
                    # Emit a warning for each unused variable, but no more that one warning per line
                    reported_linenrs = set()
                    for func_param in func_param_list:
                        if func_param.nameToken:
                            linenr = func_param.nameToken
                            if linenr not in reported_linenrs:
                                self.reportError(func_param.nameToken, 2, 7)
                                reported_linenrs.add(linenr)
                        else:
                            linenr = func.tokenDef.linenr
                            if linenr not in reported_linenrs:
                                self.reportError(func.tokenDef, 2, 7)
                                reported_linenrs.add(linenr)

My guess is reg and addr were being considered as data types and not data variables that could be represented by token.variable? I would need to understand how to debug the misra addon to provide a conclusive answer.

@adeebshihadeh
Copy link
Contributor

Nice job tracking this down, probably worth opening an issue with cppcheck.

@adeebshihadeh adeebshihadeh merged commit c118c28 into commaai:master Jan 17, 2024
9 checks passed
@0x41head 0x41head deleted the misra-c2012-2.7 branch January 17, 2024 12:01
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

Successfully merging this pull request may close these issues.

2 participants