Skip to content

Commit

Permalink
Tweak Cppcheck suppression and use build directory
Browse files Browse the repository at this point in the history
Cppcheck is under active development and its command-line options can
change. This commit updates the suppression list to work with versions
1.9 through 2.6. Additionally, while using a build directory for
Cppcheck is optional, it is recommended to store analyzer output in a
dedicated directory.

Change-Id: I0a3043332661e7b4dc32dadf896cb4792774cdcd
  • Loading branch information
jserv committed Feb 23, 2025
1 parent a30f81a commit 64d617f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ qtest
.devcontainer
core*
.cmd_history
.out

# ctags files
TAGS
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ clean:
(cd traces; rm -f *~)

distclean: clean
rm -f .cmd_history
-rm -f .cmd_history
-rm -rf .out

-include $(deps)
15 changes: 14 additions & 1 deletion scripts/pre-commit.hook
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,32 @@ done
# We suppress the checkLevelNormal warning for Cppcheck versions 2.11 and above.
# Please refer to issues/153 for more details.
CPPCHECK_suppresses="--inline-suppr harness.c \
--suppress=unmatchedSuppression \
--suppress=normalCheckLevelMaxBranches \
--suppress=missingIncludeSystem \
--suppress=noValidConfiguration \
--suppress=unusedFunction \
--suppress=identicalInnerCondition:log2_lshift16.h \
--suppress=nullPointerRedundantCheck:report.c \
--suppress=nullPointerRedundantCheck:harness.c \
--suppress=nullPointerOutOfMemory:harness.c \
--suppress=staticFunction:harness.c \
--suppress=nullPointerRedundantCheck:queue.c \
--suppress=constParameterPointer:queue.c \
--suppress=nullPointer:queue.c \
--suppress=nullPointer:qtest.c \
--suppress=returnDanglingLifetime:report.c \
--suppress=constParameterCallback:console.c \
--suppress=constParameterPointer:console.c \
--suppress=staticFunction:console.c \
--suppress=checkLevelNormal:log2_lshift16.h \
--suppress=preprocessorErrorDirective:random.h \
--suppress=constVariablePointer:linenoise.c \
--suppress=staticFunction:linenoise.c \
--suppress=nullPointerOutOfMemory:web.c \
--suppress=staticFunction:web.c \
"
CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched ."
CPPCHECK_OPTS="-I. --enable=all --error-exitcode=1 --force $CPPCHECK_suppresses $CPPCHECK_unmatched --cppcheck-build-dir=.out ."

RETURN=0
CLANG_FORMAT=$(which clang-format)
Expand All @@ -32,6 +43,7 @@ if [ $? -ne 0 ]; then
fi

CPPCHECK=$(which cppcheck)
mkdir -p .out
if [ $? -ne 0 ]; then
echo "[!] cppcheck not installed. Unable to perform static analysis." >&2
exit 1
Expand Down Expand Up @@ -127,6 +139,7 @@ do
done

# static analysis
echo "Running static analysis..."
$CPPCHECK $CPPCHECK_OPTS >/dev/null
if [ $? -ne 0 ]; then
RETURN=1
Expand Down

0 comments on commit 64d617f

Please sign in to comment.