|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -CPPCHECK_unmatched= |
4 |
| -for f in *.c; do |
5 |
| - CPPCHECK_unmatched="$CPPCHECK_unmatched --suppress=unmatchedSuppression:$f" |
6 |
| -done |
7 |
| - |
8 |
| -# We suppress the checkLevelNormal warning for Cppcheck versions 2.11 and above. |
9 |
| -# Please refer to issues/153 for more details. |
10 |
| -CPPCHECK_suppresses="--inline-suppr harness.c \ |
11 |
| ---suppress=checkersReport \ |
12 |
| ---suppress=unmatchedSuppression \ |
13 |
| ---suppress=normalCheckLevelMaxBranches \ |
14 |
| ---suppress=missingIncludeSystem \ |
15 |
| ---suppress=noValidConfiguration \ |
16 |
| ---suppress=unusedFunction \ |
17 |
| ---suppress=identicalInnerCondition:log2_lshift16.h \ |
18 |
| ---suppress=nullPointerRedundantCheck:report.c \ |
19 |
| ---suppress=nullPointerRedundantCheck:harness.c \ |
20 |
| ---suppress=nullPointerOutOfMemory:harness.c \ |
21 |
| ---suppress=staticFunction:harness.c \ |
22 |
| ---suppress=nullPointerRedundantCheck:queue.c \ |
23 |
| ---suppress=constParameterPointer:queue.c \ |
24 |
| ---suppress=memleak:queue.c \ |
25 |
| ---suppress=nullPointer:queue.c \ |
26 |
| ---suppress=nullPointer:qtest.c \ |
27 |
| ---suppress=returnDanglingLifetime:report.c \ |
28 |
| ---suppress=constParameterCallback:console.c \ |
29 |
| ---suppress=constParameterPointer:console.c \ |
30 |
| ---suppress=staticFunction:console.c \ |
31 |
| ---suppress=checkLevelNormal:log2_lshift16.h \ |
32 |
| ---suppress=preprocessorErrorDirective:random.h \ |
33 |
| ---suppress=constVariablePointer:linenoise.c \ |
34 |
| ---suppress=staticFunction:linenoise.c \ |
35 |
| ---suppress=nullPointerOutOfMemory:web.c \ |
36 |
| ---suppress=staticFunction:web.c \ |
37 |
| -" |
38 |
| -CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched --cppcheck-build-dir=.out ." |
| 3 | +# Build unmatched suppressions for each *.c file. |
| 4 | +cppcheck_build_unmatched() { |
| 5 | + local file suppression="" |
| 6 | + for file in *.c; do |
| 7 | + suppression+=" --suppress=unmatchedSuppression:$file" |
| 8 | + done |
| 9 | + echo "$suppression" |
| 10 | +} |
| 11 | + |
| 12 | +cppcheck_suppressions() { |
| 13 | + # Array of suppression keys (plain elements, without "--suppress=") |
| 14 | + local -a suppr_keys=( |
| 15 | + "checkersReport" |
| 16 | + "unmatchedSuppression" |
| 17 | + "normalCheckLevelMaxBranches" |
| 18 | + "missingIncludeSystem" |
| 19 | + "noValidConfiguration" |
| 20 | + "unusedFunction" |
| 21 | + "identicalInnerCondition:log2_lshift16.h" |
| 22 | + "checkLevelNormal:log2_lshift16.h" |
| 23 | + "nullPointerRedundantCheck:report.c" |
| 24 | + "returnDanglingLifetime:report.c" |
| 25 | + "nullPointerRedundantCheck:harness.c" |
| 26 | + "nullPointerOutOfMemory:harness.c" |
| 27 | + "staticFunction:harness.c" |
| 28 | + "nullPointerRedundantCheck:queue.c" |
| 29 | + "constParameterPointer:queue.c" |
| 30 | + "memleak:queue.c" |
| 31 | + "nullPointer:queue.c" |
| 32 | + "nullPointer:qtest.c" |
| 33 | + "constParameterCallback:console.c" |
| 34 | + "constParameterPointer:console.c" |
| 35 | + "staticFunction:console.c" |
| 36 | + "preprocessorErrorDirective:random.h" |
| 37 | + "constVariablePointer:linenoise.c" |
| 38 | + "staticFunction:linenoise.c" |
| 39 | + "nullPointerOutOfMemory:web.c" |
| 40 | + "staticFunction:web.c" |
| 41 | + ) |
| 42 | + |
| 43 | + # Array for additional cppcheck options (non-suppressions) |
| 44 | + local -a other_flags=( |
| 45 | + "--inline-suppr harness.c" |
| 46 | + ) |
| 47 | + |
| 48 | + local out="" |
| 49 | + # Append other flags. |
| 50 | + for flag in "${other_flags[@]}"; do |
| 51 | + out+="$flag " |
| 52 | + done |
| 53 | + |
| 54 | + # Append each suppression flag separately. |
| 55 | + for key in "${suppr_keys[@]}"; do |
| 56 | + out+="--suppress=$key " |
| 57 | + done |
| 58 | + |
| 59 | + # Trim trailing whitespace and output the final string. |
| 60 | + printf "%s" "$out" | sed 's/[[:space:]]*$//' |
| 61 | +} |
| 62 | + |
| 63 | +CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1" |
| 64 | +CPPCHECK_OPTS+=" --force $(cppcheck_suppressions) $(cppcheck_build_unmatched)" |
| 65 | +CPPCHECK_OPTS+=" --cppcheck-build-dir=.out ." |
39 | 66 |
|
40 | 67 | RETURN=0
|
41 | 68 | CLANG_FORMAT=$(which clang-format)
|
|
0 commit comments