@@ -91,7 +91,7 @@ detect_cc_std() {
91
91
CPPCHECK_OPTS=" -I. --enable=all --error-exitcode=1"
92
92
CPPCHECK_OPTS+=" $( detect_cc_std) "
93
93
CPPCHECK_OPTS+=" --force $( cppcheck_suppressions) $( cppcheck_build_unmatched) "
94
- CPPCHECK_OPTS+=" --cppcheck-build-dir=.out . "
94
+ CPPCHECK_OPTS+=" --cppcheck-build-dir=.out"
95
95
96
96
set_colors
97
97
@@ -179,8 +179,8 @@ if [ "${#binary_files[@]}" -gt 0 ]; then
179
179
printf " ${RED} [!]${NC} Binary data found.\n"
180
180
fi
181
181
182
- FILES =$( git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h)$" )
183
- for FILE in $FILES ; do
182
+ C_FILES =$( git diff --cached --name-only --diff-filter=ACMR | grep -E " \.(c|cpp|h|hpp )$" )
183
+ for FILE in $C_FILES ; do
184
184
nf=$( git checkout-index --temp $FILE | cut -f 1)
185
185
tempdir=$( mktemp -d) || exit 1
186
186
newfile=$( mktemp ${tempdir} /${nf} .XXXXXX) || exit 1
221
221
root=$( git rev-parse --show-toplevel)
222
222
banned=" ([^f]gets\()|(sprintf\()|(strcpy\()"
223
223
status=0
224
- for file in $( git diff --staged --name-only | grep -E " \.(c|cc|cpp|h|hh|hpp)\$ " )
225
- do
224
+ for file in $C_FILES ; do
226
225
filepath=" ${root} /${file} "
227
226
output=$( grep -nrE " ${banned} " " ${filepath} " )
228
227
if [ ! -z " ${output} " ]; then
@@ -242,7 +241,7 @@ if [ ! -f fmtscan ]; then
242
241
throw " Fail to build 'fmtscan' tools"
243
242
fi
244
243
fi
245
- if git diff --cached --name-only | grep -qiE " \.(c|h|cpp|hpp)$ " ; then
244
+ if [ -n " $C_FILES " ] ; then
246
245
echo " Running fmtscan..."
247
246
./fmtscan
248
247
if [ $? -ne 0 ]; then
@@ -251,13 +250,15 @@ if git diff --cached --name-only | grep -qiE "\.(c|h|cpp|hpp)$"; then
251
250
fi
252
251
253
252
# static analysis
254
- echo " Running static analysis..."
255
- $CPPCHECK $CPPCHECK_OPTS > /dev/null
256
- if [ $? -ne 0 ]; then
257
- RETURN=1
258
- echo " " >&2
259
- echo " Fail to pass static analysis." >&2
260
- echo
253
+ if [ -n " $C_FILES " ]; then
254
+ echo " Running static analysis..."
255
+ $CPPCHECK $CPPCHECK_OPTS $C_FILES > /dev/null
256
+ if [ $? -ne 0 ]; then
257
+ RETURN=1
258
+ echo " " >&2
259
+ echo " Fail to pass static analysis." >&2
260
+ echo
261
+ fi
261
262
fi
262
263
263
264
# non-ASCII filenames are not allowed.
0 commit comments