Accurate MISRA scanning for all rules now in place

This commit is contained in:
Josh Stewart 2022-09-08 12:57:05 +10:00
parent cf45e6c289
commit 7eee585f6b
4 changed files with 89 additions and 56 deletions

View File

@ -29,15 +29,21 @@ function parse_command_line() {
function run_cppcheck() { function run_cppcheck() {
shopt -s nullglob nocaseglob shopt -s nullglob nocaseglob
for i in "$source_folder"/*.{"$file_exts",}; do for i in "$source_folder"/*.{"$file_exts",}; do
"$cppcheck_bin" \ # cppcheck currently has no way of excluding files that are #include'd. If maths.ino is scanned on versions of cppcheck 2.8+, the scan will run for a significant period of time (15+ mins) due to all the static code from libdivide.
--inline-suppr \ # All violations from included libraries (*src* folders) are ignored
--language=c++ \ if [[ $i != *"maths.ino"* ]]; then
--addon="$script_folder/misra.json" \ "$cppcheck_bin" \
--suppressions-list="$script_folder/suppressions.txt" \ --inline-suppr \
-DCORE_AVR=1 \ --language=c++ \
-D__AVR_ATmega2560__ \ --addon="$script_folder/misra.json" \
--quiet \ --suppressions-list="$script_folder/suppressions.txt" \
$i 2>> "$cpp_result_file" --platform=avr8 \
-DCORE_AVR=1 \
-D__AVR_ATmega2560__ \
--suppress="*:*src*" \
--report-progress \
$i 2>> "$cpp_result_file"
fi
done done
shopt -u nullglob nocaseglob shopt -u nullglob nocaseglob
} }
@ -49,8 +55,8 @@ function process_cpp_results() {
sed '$!N;$!N;s/\n/~/g' < "$cpp_result_file" |\ sed '$!N;$!N;s/\n/~/g' < "$cpp_result_file" |\
# Remove duplicate lines # Remove duplicate lines
sort | uniq > "$intermediate_file" sort | uniq > "$intermediate_file"
# Count error lines # Count lines for Mandatory or Required rules
local __error_count=`grep -i "Mandatory" < "$intermediate_file" | wc -l` local __error_count=`grep -i "Mandatory\|Required" < "$intermediate_file" | wc -l`
# Unfold the line groups for readability # Unfold the line groups for readability
tr '~' '\n' < "$intermediate_file" > "$result_file" tr '~' '\n' < "$intermediate_file" > "$result_file"
rm -f "$intermediate_file" rm -f "$intermediate_file"

View File

@ -10,17 +10,17 @@ No text specified
Rule 2.2 Rule 2.2
No text specified No text specified
Rule 2.3 Rule 2.3
No text specified Advisory - All defined types must be used. IE No unused types should be defined.
Rule 2.4 Rule 2.4
No text specified No text specified
Rule 2.5 Rule 2.5
No text specified Advisory - Macro declared but not used
Rule 2.6 Rule 2.6
No text specified No text specified
Rule 2.7 Rule 2.7
No text specified Advisory - All function parameters must be used
Rule 3.1 Rule 3.1
Mandatory - /* and // cannot used within a comment (ie No nested comments) Required - /* and // cannot used within a comment (ie No nested comments)
Rule 3.2 Rule 3.2
No text specified No text specified
Rule 4.1 Rule 4.1
@ -32,9 +32,9 @@ No text specified
Rule 5.2 Rule 5.2
No text specified No text specified
Rule 5.3 Rule 5.3
Mandatory - An identifier (variable) in an outer scope shall not be redfined within an inner scope Required - An identifier (variable) in an outer scope shall not be redfined within an inner scope
Rule 5.4 Rule 5.4
Mandatory - Macro names must be unique Required - Macro names must be unique
Rule 5.5 Rule 5.5
No text specified No text specified
Rule 5.6 Rule 5.6
@ -42,7 +42,7 @@ No text specified
Rule 5.7 Rule 5.7
No text specified No text specified
Rule 5.8 Rule 5.8
No text specified Required - All identifiers must be unique
Rule 5.9 Rule 5.9
No text specified No text specified
Rule 6.1 Rule 6.1
@ -52,7 +52,7 @@ No text specified
Rule 7.1 Rule 7.1
No text specified No text specified
Rule 7.2 Rule 7.2
No text specified Required - All unsigned integer constants must have a 'u' or 'U' suffix
Rule 7.3 Rule 7.3
No text specified No text specified
Rule 7.4 Rule 7.4
@ -60,23 +60,25 @@ No text specified
Rule 8.1 Rule 8.1
No text specified No text specified
Rule 8.2 Rule 8.2
No text specified Required - Function prototypes must have named parameters or void if none
Rule 8.3 Rule 8.3
No text specified No text specified
Rule 8.4 Rule 8.4
No text specified Required - Functions must have a prototype and prototype arguements/return types must match
Rule 8.5
Required - An object or function must only be declared once
Rule 8.6 Rule 8.6
No text specified Required - Externally identified object must be defined once and only once (Object has not been defined or was defined in multiple places)
Rule 8.7 Rule 8.7
No text specified Advisory - Objects and functions should only be made available externally if required
Rule 8.8 Rule 8.8
No text specified No text specified
Rule 8.9 Rule 8.9
No text specified No text specified
Rule 8.10 Rule 8.10
No text specified Required - All inline functions should be declared static
Rule 8.11 Rule 8.11
No text specified Advisory - Externally available arrays must have an explicitely declared size
Rule 8.12 Rule 8.12
No text specified No text specified
Rule 8.13 Rule 8.13
@ -94,27 +96,27 @@ No text specified
Rule 9.5 Rule 9.5
No text specified No text specified
Rule 10.1 Rule 10.1
Mandatory - Operations must be of an essentially correct type (Eg no shift on signed values, comparison is not boolean, incrementing/decrementing a bool etc) Required - Operations must be of an essentially correct type (Eg no shift on signed values, comparison is not boolean, incrementing/decrementing a bool etc)
Rule 10.2 Rule 10.2
No text specified No text specified
Rule 10.3 Rule 10.3
No text specified Required - The value from an expression must only be assigned to an object with the same or larger essential type
Rule 10.4 Rule 10.4
Mandatory - The target of an operation must be of an appropriate type Required - The target of an operation must be of an appropriate type. Eg No implicit conversion of signed/unsigned.
Rule 10.5 Rule 10.5
No text specified No text specified
Rule 10.6 Rule 10.6
Mandatory - An expression should not assign a value to a variable of a narrower or essentially different type Required - An expression should not assign a value to a variable of a narrower or essentially different type
Rule 10.7 Rule 10.7
No text specified Required - Complex int expression requires cast when widening objects
Rule 10.8 Rule 10.8
No text specified Required - A composite expression value should not be cast to a wider type or a different essential type
Rule 11.1 Rule 11.1
No text specified No text specified
Rule 11.2 Rule 11.2
No text specified No text specified
Rule 11.3 Rule 11.3
Mandatory - A cast shall not be performed between a pointer to object type and a pointer to a different object type Required - A cast shall not be performed between a pointer to object type and a pointer to a different object type
Rule 11.4 Rule 11.4
Advisory - Object pointers should not be treated as or converted to integers Advisory - Object pointers should not be treated as or converted to integers
Rule 11.5 Rule 11.5
@ -126,11 +128,11 @@ No text specified
Rule 11.8 Rule 11.8
No text specified No text specified
Rule 11.9 Rule 11.9
Mandatory - An integer null pointer shall have no value assigned other than NULL macro Required - An integer null pointer shall have no value assigned other than NULL macro
Rule 12.1 Rule 12.1
Advisory - Order of operations within an expression must be explicit. Multiple conditions in a logical operation should have brackets around them. Advisory - Order of operations within an expression must be explicit. Multiple conditions in a logical operation should have brackets around them.
Rule 12.2 Rule 12.2
No text specified Required - Right hand side of a shift operation must not exceed the width of the essential value. Potential shift too far or negative shift.
Rule 12.3 Rule 12.3
Advisory - The comma operator is not permitted. Advisory - The comma operator is not permitted.
Rule 12.4 Rule 12.4
@ -154,7 +156,7 @@ No text specified
Rule 14.3 Rule 14.3
No text specified No text specified
Rule 14.4 Rule 14.4
Mandatory - Non-Boolean type expression used in an if statement or the conditional iteration statement of a loop Required - Non-Boolean type expression used in an if statement or the conditional iteration statement of a loop
Rule 15.1 Rule 15.1
No text specified No text specified
Rule 15.2 Rule 15.2
@ -166,17 +168,17 @@ No text specified
Rule 15.5 Rule 15.5
Advisory - A function should only have a single return point Advisory - A function should only have a single return point
Rule 15.6 Rule 15.6
Mandatory - Loops, switch and if/else statements must have brackets around their body Required - Loops, switch and if/else statements must have brackets around their body
Rule 15.7 Rule 15.7
Mandatory - 'else if' statements must terminate with a final 'else' Required - 'else if' statements must terminate with a final 'else'
Rule 16.1 Rule 16.1
No text specified No text specified
Rule 16.2 Rule 16.2
No text specified No text specified
Rule 16.3 Rule 16.3
Mandatory - All cases within switchs must have an unconditional break statement Required - All cases within switches must have an unconditional break statement
Rule 16.4 Rule 16.4
Mandatory - All switch statements must have a default case Required - All switch statements must have a default case
Rule 16.5 Rule 16.5
No text specified No text specified
Rule 16.6 Rule 16.6
@ -186,9 +188,9 @@ No text specified
Rule 17.1 Rule 17.1
No text specified No text specified
Rule 17.2 Rule 17.2
Mandatory - Functions shall not call themselves, either directly or indirectly Required - Functions shall not call themselves, either directly or indirectly
Rule 17.3 Rule 17.3
No text specified Mandatory - No implicit function declarations
Rule 17.4 Rule 17.4
No text specified No text specified
Rule 17.5 Rule 17.5
@ -196,7 +198,7 @@ No text specified
Rule 17.6 Rule 17.6
No text specified No text specified
Rule 17.7 Rule 17.7
Mandatory - The value returned by a function having non-void return type shall be used Required - The value returned by a function having non-void return type shall be used
Rule 17.8 Rule 17.8
Advisory - An argument to a function should be treated as read-only Advisory - An argument to a function should be treated as read-only
Rule 18.1 Rule 18.1
@ -220,11 +222,11 @@ No text specified
Rule 19.2 Rule 19.2
No text specified No text specified
Rule 20.1 Rule 20.1
Mandatory - Only comments and prepropccesor directives can come before #include statements Required - Only comments and prepropccesor directives can come before #include statements
Rule 20.2 Rule 20.2
No text specified No text specified
Rule 20.3 Rule 20.3
Mandatory - #include statements must be followed by a filename Required - #include statements must be followed by a filename
Rule 20.4 Rule 20.4
No text specified No text specified
Rule 20.5 Rule 20.5
@ -232,7 +234,7 @@ Advisory - Use of #undef is not permitted
Rule 20.6 Rule 20.6
No text specified No text specified
Rule 20.7 Rule 20.7
Mandatory - Macro expressions must be enclosed in parentheses Required - Macro expressions and parameters must be enclosed in parentheses
Rule 20.8 Rule 20.8
No text specified No text specified
Rule 20.9 Rule 20.9
@ -252,7 +254,7 @@ No text specified
Rule 21.2 Rule 21.2
No text specified No text specified
Rule 21.3 Rule 21.3
Mandatory - Memory allocation functions (Eg malloc(), talloc() etc) shall not be used Required - Memory allocation functions (Eg malloc(), talloc() etc) shall not be used
Rule 21.4 Rule 21.4
No text specified No text specified
Rule 21.5 Rule 21.5
@ -262,7 +264,7 @@ No text specified
Rule 21.7 Rule 21.7
No text specified No text specified
Rule 21.8 Rule 21.8
No text specified Required - Termination functions from stdlib (Eg exit, abort etc) shall not be used
Rule 21.9 Rule 21.9
No text specified No text specified
Rule 21.10 Rule 21.10

View File

@ -1,2 +1 @@
5.4 - cppcheck currently doesn't appear to handle the scope of #defines within header files and so is counting all instances as duplicates.
10.4 - Currently suppressing this as the work required to go through and add I, U, UL, L etc to all the contstants is not worth it.

View File

@ -1,6 +1,32 @@
misra_10.4 #All Advisory rules are suppressed:
misra_5.4 misra-c2012-1.2
MISRA_16_4:misra-suppressions1-test.c misra-c2012-2.3
MISRA.16.6:misra-suppressions1-test.c misra-c2012-2.4
MISRA_4_1:misra-suppressions2-test.c misra-c2012-2.5
MISRA.19_2:misra-suppressions2-test.c misra-c2012-2.6
misra-c2012-2.7
misra-c2012-4.2
misra-c2012-5.9
misra-c2012-8.7
misra-c2012-8.9
misra-c2012-8.13
misra-c2012-10.5
misra-c2012-11.4
misra-c2012-11.5
misra-c2012-12.1
misra-c2012-12.3
misra-c2012-12.4
misra-c2012-13.3
misra-c2012-13.4
misra-c2012-15.1
misra-c2012-15.4
misra-c2012-15.5
misra-c2012-17.5
misra-c2012-17.8
misra-c2012-18.4
misra-c2012-18.5
misra-c2012-19.2
misra-c2012-20.1
misra-c2012-20.5
misra-c2012-20.10
misra-c2012-21.12