-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint suggestions based on MISRA 2004 #2227
Comments
I'd like to take some of these on! I already have a lint prepared for else if branches without an else. |
I think many more of these are solved by the language/compiler than are checked off. Someone with edit privileges may want to update the list. |
Yeah, I realized that too. We can definitely cross off the following:
|
Thanks. I only went through the list quickly. Feel free to post if I need to update any others. |
Maybe it would be better to analyze rulesets from other (more similar) languages as well (e.g. ADA or C++). C++:
Ada: |
SPARK Ada is a "safer" subset designed for easier verification of safety critical systems |
While that's true, it still requires manual verification of the code, including setting up invariants, etc. Are there no rule sets or lints for security relevant Ada code? |
I didn't see any when I worked in aerospace. But then no new projects were done in Ada only legacy code used it. The lack of support for Ada in certain testing and analysis tools meant those parts of the code were painful as we had to manually verify 😢 |
@xd009642 I'm no expert on Ada, but wouldn't the Ravenscar profile be a better comparison? I also found this wikipedia article on Coding conventions which lists 4 coding styles for Ada (including ones from NASA and ESA). Additionally, I don't think that the availability of tooling (or lack thereof) is that relevant here - those rules still might be interesting for Rust (or clippy). |
Well all the C/C++ standards we used had a lot of automated tooling and static analysis which automated the strenuous parts of reviewing. And I'm not familiar with Ravenscar, the legacy projects (systems on jets) I worked on used the SPARK subset or a standard written specifically for the project. As well as looking at other coding standards could also peruse standards like DO-178B (aerospace), ISO 26262 (automotive) etc. to see what they assurances they need at the various safety levels |
Btw. re-reading the list above, the "no bitwise ops on signed ints" rule stood out, because it may be problematic in C, unlike in Rust. So we might want to have a fourth category "unneeded because of different semantics"... |
@xd009642 I know that Misra and other standards are (partly or mostly) checked by tools like QA-C or similar, but what I meant was: Just because these tools might not exist for Ada does not mean that one shouldn't have a look at those rules (because we might implement them for Rust). I agree that safety standards for those various domains should be considered. @llogiq That's why I mentioned those other coding standards - many of those rules definitely make sense for C, but not for Rust. It could provide a simple way to filter out C-specific rules. |
I don't understand most of the rules, could you please give me some more details?
how is this an issue in rust?
so this would become a clippy warning?
Probably mutable static vars? Anyway, is this really an rust issue?
Not rust related afaik?
Can you give an example of 'comples' expression?
So this would trigger a warning?
How is
How this applies to rust?
How is
Too general. In some cases, multiple returns or breaks improves readability
Why??? I know recursion may cause stack overflow easily, but come on. A lot of functions have nice recursive versions. Not every recursion is easy to change into iteration. Tail recursion may be optimized by the compiler.
Is this applicable to rust?
How can this affect the rust code negatively?
No more custom
So no more
Why? How? |
Does it really make sense to collect & discuss those rules here? There a discussion could take place in order to find a set of rules that
Edit: Prototype can be found in this repo. |
a very related analysis: https://github.com/PolySync/misra-rust/blob/master/MISRA-Rules.md |
As mentioned in #2215 I'm compiling a list of lints based on MISRA rules. For the C language MISRA 2004 defines C90 should be used so there are numerous rules forbidding certain C99 features, C++ features. And there are also rules written for machines which provide FPUs that don't use IEEE754 for floats. So I'm going to attempt to remove all the irrelevant rules and keep it to rules which are relevant to rust 😄
So here it goes. All the relevant rules, a lot of these are probably already covered. And a number are actually already caught by the rust compiler!
let x:u8 = (8 as u8) >> 2;
&&
and||
may not contain side effects&&
and||
can only be primary expressionsa && b && c
is good,a && (b && c)
is badtrue == false
)goto
orcontinue
break
statementelse_if_without_else
Already solved by clippy
Already solved by the language
The text was updated successfully, but these errors were encountered: