35

Cppcheck allows you to create your own rules files, but I don't know how much of cppcheck's functionality is exposed.

Is anyone working on a set that would enforce JSF or MISRA rules?

orbitcowboy
  • 1,438
  • 13
  • 25
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • 2
    Do you want to check the __error__ or the __style__ issue in the code? – Sid Zhang Jul 08 '14 at 03:23
  • 1
    For example, [MISRA](http://en.wikipedia.org/wiki/MISRA_C) is strong subset of C language, it prohibits may unsafe constructions. As says wiki: "Most of the guidelines can be checked using tools that perform static code analysis." but the tools listed there are commercial. MISRA will not make the code error-free, but it is bit harder to write some errors in MISRA-confirming code. MISRA checking is mostly style checking, but still useful. – osgx Jul 23 '14 at 02:43

3 Answers3

12

You won't be able to implement all MISRA/JSF rules and directives as cppcheck rules, mostly only the straightforward ones restricting certain C language features and constructions or that are style-related (some that come to mind: spaces before/after ./->, # of arguments on a single line, use of unions to provide different methods of accessing memory, presence of unsigned/signed before char, etc).

User Ira Baxter pretty much nailed it in a comment on another question touching cppcheck: not everything can be represented/simplified as a pattern. Relying on patterns for custom rules makes it difficult to handle and detect higher level issues, related for example to types (e.g. sizeof() on types; you would have to parse and collect tokens (typedefs, enums) used as a type representation), inheritance (e.g. classes, incl. derived ones, used both as virtual and non-virtual), and scope. Those need to be hard-coded into cppcheck (you could always fork cppcheck...)

In any case, have you touched MISRA (or JSF) rules? Is this a requirement for a project? If not, you could grab a copy of the MISRA guidelines (you already have the JSF ones) and check the ones you can implement using PCRE patterns. If it is a requirement, I suggest you "invest" in a commercial product that does check for MISRA/JSF guidelines and use both tools.

A final note: you don't need all the MISRA/JSF rules, and many tools leave a small percentage of those out.

Community
  • 1
  • 1
johnwait
  • 1,135
  • 7
  • 17
  • For rules beyond pattern matching you can use the framework in [clang-tidy](http://clang.llvm.org/extra/clang-tidy.html). – legalize Feb 24 '15 at 00:05
  • @johnwait a specific rule set wasn't a requirement but having a formal set of rules was (!) and if you are going to have rules you may as well have an automated way of checking them. In the end we wrote our own list and do code reviews – Martin Beckett May 05 '15 at 03:40
2

Cppcheck has MISRA support. Here is an overview about the supported rules: supported MISRA rules

orbitcowboy
  • 1,438
  • 13
  • 25
1

From what I can tell, looking through the documentation, It looks pretty exposed. http://cppcheck.sourceforge.net/manual.pdf .

DTSCode
  • 1,062
  • 9
  • 24
  • 2
    DTSCode, thank you, but the manual have no predefined set of "MISRA" or "JSF" rules... – osgx Jul 23 '14 at 02:40