Confessions of a Wall Street Programmer

practical ideas (and perhaps some uncommon knowledge) on software architecture, design, construction and testing

cppcheck.sh

This script wraps cppcheck and supplies common parameters, as well as pre-defined compiler definitions.

Usage

cppcheck.sh [parameters] [file]

Notes

This script is normally invoked through the cc_driver.pl script, which supplies definitions from the file’s entry in the compilation database (-I and -D parameters).

The script generates a file containing the compiler’s pre-defined macro definitions, which is input to cppcheck using cppcheck’s --include= flag.

See this post for more information.

Code Listing

(cppcheck.sh) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
#
# helper script for cppcheck that defines a number of common parameters
# (also generates and includes compiler pre-defined macros)
#
# Copyright 2016 by Bill Torpey. All Rights Reserved.
# This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 United States License.
# http://creativecommons.org/licenses/by-nc-nd/3.0/us/deed.en
#

# its a very good idea to include compiler builtin definitions
TEMPFILE=$(mktemp)
cpp -dM </dev/null 2>/dev/null >${TEMPFILE}

# uncomment the following line if you need to override LD_LIBRARY_PATH for cppcheck
# note that you must also supply the required path in place of "<>"
#LD_LIBRARY_PATH=<>:$LD_LIBRARY_PATH \
cppcheck --enable=all --inconclusive \
--error-exitcode=19 \
--std=posix --std=c++03 --std=c++11 \
--include=${TEMPFILE} \
--platform=unix64 \
--suppress=unusedFunction \
--suppress=unmatchedSuppression \
--suppress=missingIncludeSystem \
$*

[[ -f ${TEMPFILE} ]] && rm -f ${TEMPFILE} 2>&1 >/dev/null

Comments