Rules supported by RuleChecker

SEI CERT C Coding Standard

Below is the list of SEI CERT rules and recommendations supported as of RuleChecker 17.10.

Light-colored items are additionally supported when using RuleChecker in conjunction with Astrée. Exclamation marks denote recom­men­da­tions that, by definition, cannot be checked for automatically by any tool. Further details are available via RuleChecker’s “Help”  menu or by contacting info@absint.com.

Preprocessor
PRE00-C Prefer inline or static functions to function-like macros
PRE01-C Use parentheses within macros around parameter names
PRE05-C Understand macro replacement when concatenating tokens
or performing stringification
!
PRE06-C Enclose header files in an inclusion guard
PRE07-C Avoid using repeated question marks
PRE32-C Do not use preprocessor directives in invocations of function-like macros
Declarations and initialization
DCL00-C Const-qualify immutable objects
DCL01-C Do not reuse variable names in subscopes
DCL07-C Include the appropriate type information in function declarators
DCL08-C Properly encode relationships in constant definitions !
DCL10-C Maintain the contract between the writer and caller of variadic functions
DCL11-C Understand the type issues associated with variadic functions !
DCL13-C Declare function parameters that are pointers to values not changed by the function as const
DCL15-C Declare file-scope objects or functions that do not need external linkage as static
DCL16-C Use L, not l, to indicate a long value
DCL17-C Beware of miscompiled volatile-qualified variables !
DCL18-C Do not begin integer constants with 0 when specifying a decimal value
DCL19-C Minimize the scope of variables and functions
DCL20-C Explicitly specify void when a function accepts no arguments
DCL21-C Understand the storage of compound literals !
DCL22-C Use volatile for data that cannot be cached !
DCL23-C Guarantee that mutually visible identifiers are unique
DCL30-C Declare objects with appropriate storage durations
DCL31-C Declare identifiers before using them
DCL36-C Do not declare an identifier with conflicting linkage classifications
DCL37-C Do not declare or define a reserved identifier
DCL38-C Use the correct syntax when declaring a flexible array member
DCL40-C Do not create incompatible declarations of the same function or object
DCL41-C Do not declare variables inside a switch statement before the first case label
Expressions
EXP02-C Be aware of the short-circuit behavior of the logical AND and OR operators
EXP03-C Do not assume the size of a structure is the sum of the sizes of its members
EXP08-C Ensure pointer arithmetic is used correctly
EXP10-C Do not depend on the order of evaluation of subexpressions
or the order in which side effects take place
EXP12-C Do not ignore values returned by functions
EXP19-C Use braces for the body of an if, for, or while statement
EXP20-C Perform explicit tests to determine success, true and false, and equality
EXP30-C Do not depend on the order of evaluation for side effects
EXP32-C Do not access a volatile object through a nonvolatile reference
EXP33-C Do not read uninitialized memory
EXP34-C Do not dereference null pointers
EXP36-C Do not cast pointers into more strictly aligned pointer types
EXP37-C Call functions with the correct number and type of arguments
EXP43-C Avoid undefined behavior when using restrict-qualified pointers
EXP44-C Do not rely on side effects in operands to sizeof, _Alignof, or _Generic
EXP45-C Do not perform assignments in selection statements
EXP46-C Do not use a bitwise operator with a Boolean-like operand
Integers
INT00-C Understand the data model used by your implementation(s) !
INT02-C Understand integer conversion rules !
INT07-C Use only explicitly signed or unsigned char type for numeric values
INT08-C Verify that all integer values are in range
INT09-C Ensure enumeration constants map to unique values
INT12-C Do not make assumptions about the type of a plain int bit-field
when used in an expression
INT13-C Use bitwise operators only on unsigned operands
INT18-C Evaluate integer expressions in a larger size before comparing
or assigning to that size
INT30-C Ensure that unsigned integer operations do not wrap
INT31-C Ensure that integer conversions do not result in lost or misinterpreted data
INT32-C Ensure that operations on signed integers do not result in overflow
INT33-C Ensure that division and remainder operations do not result in divide-by-zero errors
INT34-C Do not shift an expression by a negative number of bits
or by greater than or equal to the number of bits that exist in the operand
INT36-C Converting a pointer to integer or integer to pointer
Floating point
FLP00-C Understand the limitations of floating-point numbers !
FLP01-C Take care in rearranging floating-point expressions !
FLP02-C Avoid using floating-point numbers when precise computation is needed
FLP03-C Detect and handle floating-point errors
FLP04-C Check floating-point inputs for exceptional values
FLP06-C Convert integers to floating point for floating-point operations
FLP30-C Do not use floating-point variables as loop counters
FLP32-C Prevent or detect domain and range errors in math functions
FLP34-C Ensure that floating-point conversions are within range of the new type
Arrays
ARR00-C Understand how arrays work !
ARR02-C Explicitly specify array bounds, even if implicitly defined by an initializer
ARR30-C Do not form or use out-of-bounds pointers or array subscripts
ARR36-C Do not subtract or compare two pointers that do not refer to the same array
ARR37-C Do not add or subtract an integer to a pointer to a non-array object
Characters and strings
STR00-C Represent characters using an appropriate type
STR04-C Use plain char for characters in the basic character set
STR09-C Don’t assume numeric values for expressions with type plain character
STR11-C Do not specify the bound of a character array initialized with a string literal
STR30-C Do not attempt to modify string literals
STR31-C Guarantee that storage for strings has sufficient space
for character data and the null terminator
STR32-C Do not pass a non-null-terminated character sequence
to a library function that expects a string
STR37-C Arguments to character-handling functions must be
representable as an unsigned char
Memory management
MEM01-C Store a new value in pointers immediately after free()
MEM04-C Beware of zero-length allocations
MEM07-C Ensure that the arguments to calloc(), when multiplied, do not wrap
MEM30-C Do not access freed memory
MEM31-C Free dynamically allocated memory when no longer needed
MEM34-C Only free memory allocated dynamically
MEM35-C Allocate sufficient memory for an object
Input/output
FIO14-C Understand the difference between text mode and binary mode with file streams !
FIO37-C Do not assume that fgets() or fgetws()
returns a nonempty string when successful
FIO38-C Do not copy a FILE object
Environment
ENV33-C Do not call system()
Signals
SIG01-C Understand implementation-specific details regarding signal handler persistence !
SIG30-C Call only asynchronous-safe functions within signal handlers
SIG31-C Do not access shared objects in signal handlers
SIG34-C Do not call signal() from within interruptible signal handlers
Error handling
ERR06-C Understand the termination behavior of assert() and abort() !
ERR33-C Detect and handle standard library errors
Concurrency
CON00-C Avoid race conditions with multiple threads
CON01-C Acquire and release synchronization primitives in the same module,
at the same level of abstraction
CON03-C Ensure visibility when accessing shared variables
CON06-C Ensure that every mutex outlives the data it protects
CON32-C Prevent data races when accessing bit-fields from multiple threads
CON33-C Avoid race conditions when using library functions
CON37-C Do not call signal() in a multithreaded program
Concurrency (POSIX)
CON00-C Avoid race conditions with multiple threads
Miscellaneous
MSC01-C Strive for logical completeness
MSC04-C Use comments consistently and in a readable fashion
MSC07-C Detect and remove dead code
MSC12-C Detect and remove code that has no effect or is never executed
MSC13-C Detect and remove unused values
MSC15-C Do not depend on undefined behavior
MSC17-C Finish every set of statements associated with a case label
with a break statement
MSC20-C Do not use a switch statement to transfer control into a complex block
MSC23-C Beware of vendor-specific library and language differences
MSC24-C Do not use deprecated or obsolescent functions
MSC30-C Do not use the rand() function for generating pseudorandom numbers
MSC37-C Ensure that control never reaches the end of a non-void function
Microsoft Windows
WIN03-C Understand HANDLE inheritance !

MISRA C

RuleChecker screenshot

RuleChecker supports both MISRA-C:2004 and MISRA-C:2012, including Amendment 1. It is highly configurable, allowing you to check for individual rules and even specific aspects of certain rules.

As of RuleChecker 17.10, a total of 277 rules of the two rule sets are checked. An 11-page PDF description of how RuleChecker handles each rule is available on request. Contact info@absint.com for your free copy.

Below is just a quick overview of all the supported rule categories.

MISRA-C:2004
1Environment
2Language extensions
3Documentation
4Character sets
5Identifiers
6Types
7Constants
8Declarations and definitions
9Initialization
10Arithmetic type conversions
11Pointer type conversions
12Expressions
13Control statement expressions
14Control flow
15Switch statements
16Functions
17Pointers and arrays
18Structures and unions
19Preprocessing directives
20Standard libraries
21Run-time failures
MISRA-C:2012
DDirectives
1A standard C environment
2Unused code
3Comments
4Character sets and lexical convention
5Identifiers
6Types
7Literals and constants
8Declarations and definitions
9Initialization
10The essential type model
11Pointer type conversions
12Expressions
13Side effects
14Control statement expressions
15Control flow
16Switch statements
17Functions
18Pointers and arrays
19Overlapping storage
20Preprocessing directives
21Standard libraries
22Resources
MISRA-C:2012 Amendment 1
12Expressions
21Standard libraries

MISRA C++:2008

Support for C++ is now being implemented. The latest version of RuleChecker already supports well over 100 MISRA C++:2008 rules.

Common Weakness Enumeration (CWE)

Below is the list of supported CWE rules as of RuleChecker 17.10. This includes items with the CWE CCR accuracies Exact and CWE-more-abstract.

456Missing initialization of a variable
457Use of uninitialized variable
478Missing default case in switch statement
665Improper initialization
685Function call with incorrect number of arguments
686Function call with incorrect argument type
824Access of uninitialized pointer
908Use of uninitialized resource
The following rules are additionally supported when using RuleChecker in conjunction with Astrée. This includes items with the CWE CCR accuracies Exact, CWE-more-abstract, CWE-more-specific, and CWE-partial. For further details, see RuleChecker’s “Help”  menu or contact info@absint.com.
118Improper access of indexable resource
119Improper restriction of operations within the bounds of a memory buffer
120Buffer copy without checking size of input (‘classic buffer overflow‘)
121Stack-based buffer overflow
122Heap-based buffer overflow
123Write-what-where condition
124Buffer underwrite
125Out-of-bounds read
126Buffer over-read
127Buffer under-read
128Wrap-around error
129Improper validation of array index
130Improper handling of length parameter inconsistency
131Incorrect calculation of buffer size
170Improper null termination
188Reliance on data/memory layout
190Integer overflow or wraparound
191Integer underflow or wraparound
193Off-by-one error
194Unexpected sign extension
195Signed to unsigned conversion error
196Unsigned to signed conversion error
197Numeric truncation error
240Improper handling of inconsistent structural elements
242Use of inherently dangerous function
252Unchecked return value
253Incorrect check of function return value
362Concurrent execution using shared resource
with improper synchronization (‘race condition’)
364Signal handler race condition
365Race condition in switch
366Race condition within a thread
367Time-of-check time-of-use (TOCTOU) race condition
369Divde by zero
398Indicator of poor code quality
404Improper resource shutdown or release
411Resource locking problems
415Double free
416Use after free
466Return of pointer value outside of expected range
471Modification of assumed-immutable data (MAID)
475Undefined behavior for input to API
476NULL pointer dereference
561Dead code
567Unsynchronized access to shared data in a multithreaded context
573Improper following of specification by caller
587Assignment of a fixed address to a pointer
588Attempt to access child of a nonstructure pointer
628Function call with incorrectly specified arguments
662Improper synchronization
667Improper locking
672Operation on a resource after expiration or release
680Integer overflow to buffer overflow
681Incorrect conversion between numeric types
682Incorrect calculation
690Unchecked return value to NULL pointer dereference
754Improper check for unusual or exceptional conditions
761Free of pointer not at start of buffer
763Release of invalid pointer or reference
764Multiple locks of a critical resource
765Multiple unlocks of a critical resource
785Use of path manipulation function without maximum-sized buffer
786Access of memory location before start of buffer
787Out-of-bounds write
805Buffer access with incorrect length value
806Buffer access using size of source buffer
823Use of out-of-range pointer offset
825Expired pointer dereference
832Unlock of a resource that is not locked
835Loop with unreachable exit condition (‘infinite loop’)

ISO/IEC

Below is the list of ISO/IEC rules and diagnostics supported as of RuleChecker 17.10. Further details are available via RuleChecker’s “Help”  menu or by contacting info@absint.com.

ISO/IEC TS 17961:2013 (C Secure Coding Rules)

2Accessing freed memory
6Calling functions with incorrect arguments
10Converting a pointer to integer or integer to pointer
11Converting pointer values to more strictly aligned pointer types
12Copying a FILE object
13Declaring the same function or object in incompatible ways
14Dereferencing an out-of-domain pointer
15Escaping of the address of an automatic object
17Use of an implied default in a switch statement
21Allocating insufficient memory
22Forming or using out-of-bounds pointers or array subscripts
23Freeing memory multiple times
26Integer division errors
28Modifying string literals
29Modifying the string returned by getenv, localeconv, setlocale, and strerror
30Overflowing signed integers
34Reallocating or freeing memory that was not dynamically allocated
35Referencing uninitialized memory
36Subtracting or comparing two pointers that do not refer to the same array
38Taking the size of a pointer to determine the size of the pointed-to type
39Using a tainted value as an argument to an unprototyped function pointer
44Using identifiers that are reserved for the implementation
46Tainted, potentially mutilated, or out-of-domain integer values are used in a restricted sink

ISO/IEC 9899:1999 diagnostics

Constraint violations
6.2.7p2 Two declarations that declare the same entity must be of compatible type
6.2.7p2 At least one type specifier shall be given in a declaration
6.5.2.2p2 The number of arguments shall agree with the number of parameters
6.5.4p3 No implicit conversion shall be performed between pointer types and integer types
6.7.5.2p1 If the size expression of an array declarator is constant, it shall have a value greater than zero
6.7.10p2 The constant expression of a static assert shall compare unequal to zero
Language extensions
4p5 Assembler code shall be avoided
4p5 Data placement at an absolute location shall be avoided
4p5 Enums shall not be forward-declared, i.e. used as complete type before being defined
4p5 Lvalue casts shall be avoided
4p5 Non-standard keywords shall not be used
4p5 Pointer attributes shall be avoided
4p5 GCC’s statement expressions shall not be used
6.5.1p2 Implicit function declaration shall not be used
6.6p10 Only integer constant expressions stricly conforming to the C standard shall be used
Implementation-defined behavior
6.3.2.3p5+6 No cast shall be performed between pointer types and integer types
6.4.4.4p10 The value of an integer character constant containing more than one character is implementation-defined
Unspecified behavior
6.5 The result of the evaluation of an expression shall not depend on the order of evaluation of subexpressions
6.7.8 The result of the evaluation of an initializer list expression shall not depend on the order of evaluation of elements and subexpressions

RuleChecker automatically compiles various code metrics. For each metric, you can optionally specify thresholds to check your code against, essentially creating additional rules of your own.

Metrics

Comment density
Cyclomatic complexity
Number of return statements
Number of goto statements
Number of instructions per function
Number of parameters
Number of maintainable code lines
Maximum nesting of control structures
Maximum number of execution paths
Number of called functions
Number of calling functions
Number of recursive paths
Language scope
Comment density (HIS)

Other rules

Customer-specific rules

We have experience with extending RuleChecker for various customers with their very own in-house rule sets. Please contact info@absint.com with any questions.

Style rules

These optional rules cover the naming of all C identifiers. For each kind of identifier, you can specify a maximum and minimum length, and check the spelling using regular expressions.

Function naming
All functions
Global functions
Static functions
Parameters
Macro naming
All macros
Function-like macros
Object-like macros
Member naming
All members
Struct members
Union members
Bitfields
Object naming
All objects
Global objects
Static objects
Local objects
Tag naming
All tags
Enumeration tags
Struct tags
Union tags
Type naming
All types
Struct types
Enumeration naming
Enumeration constants
Miscellaneous
8 additional rules