forked from OSGeo/PROJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcppcheck.sh
executable file
·378 lines (305 loc) · 8.79 KB
/
cppcheck.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#!/bin/bash
echo `cppcheck --version`
LOG_FILE=/tmp/cppcheck_proj.txt
SCRIPT_DIR=$(dirname "$0")
case $SCRIPT_DIR in
"/"*)
;;
".")
SCRIPT_DIR=$(pwd)
;;
*)
SCRIPT_DIR=$(pwd)/$(dirname "$0")
;;
esac
TOPDIR="$SCRIPT_DIR/.."
echo "" > ${LOG_FILE}
for dirname in ${TOPDIR}/src; do
echo "Running cppcheck on $dirname... (can be long)"
if ! cppcheck --inline-suppr --template='{file}:{line},{severity},{id},{message}' \
--enable=all --inconclusive --std=posix \
-DCPPCHECK -D__cplusplus=201103L -DNAN \
-I${TOPDIR}/src -I${TOPDIR}/include \
"$dirname" \
-j 8 >>${LOG_FILE} 2>&1 ; then
echo "cppcheck failed"
exit 1
fi
done
ret_code=0
grep -v "unmatchedSuppression" ${LOG_FILE} \
| grep -v "nn.hpp" \
| grep -v "nlohmann/json.hpp" \
| grep -v "wkt1_generated_parser" \
| grep -v "wkt2_generated_parser" \
| grep -v "passedByValue,Function parameter 'coo' should be passed by const reference" \
| grep -v "passedByValue,Function parameter 'lpz' should be passed by const reference" \
| grep -v "passedByValue,Function parameter 'xyz' should be passed by const reference" \
| grep -v "passedByValue,Function parameter 'in' should be passed by const reference" \
| grep -v "knownConditionTrueFalse,Condition '!allowEmptyIntersection' is always false" \
| grep -v -e "unitconvert.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \
| grep -v -e "helmert.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \
| grep -v -e "molodensky.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \
| grep -v -e "vgridshift.*unreadVariable,Variable 'point.*' is assigned a value that is never used" \
> ${LOG_FILE}.tmp
mv ${LOG_FILE}.tmp ${LOG_FILE}
if grep "null pointer" ${LOG_FILE} ; then
echo "Null pointer check failed"
ret_code=1
fi
if grep "duplicateBreak" ${LOG_FILE} ; then
echo "duplicateBreak check failed"
ret_code=1
fi
if grep "duplicateBranch" ${LOG_FILE} ; then
echo "duplicateBranch check failed"
ret_code=1
fi
if grep "uninitMemberVar" ${LOG_FILE} ; then
echo "uninitMemberVar check failed"
ret_code=1
fi
if grep "useInitializationList" ${LOG_FILE} ; then
echo "uninitMemberVar check failed"
ret_code=1
fi
if grep "clarifyCalculation" ${LOG_FILE} ; then
echo "clarifyCalculation check failed"
ret_code=1
fi
if grep "invalidPrintfArgType_uint" ${LOG_FILE} ; then
echo "invalidPrintfArgType_uint check failed"
ret_code=1
fi
if grep "catchExceptionByValue" ${LOG_FILE} ; then
echo "catchExceptionByValue check failed"
ret_code=1
fi
if grep "memleakOnRealloc" ${LOG_FILE} ; then
echo "memleakOnRealloc check failed"
ret_code=1
fi
if grep "arrayIndexOutOfBoundsCond" ${LOG_FILE} ; then
echo "arrayIndexOutOfBoundsCond check failed"
ret_code=1
fi
if grep "arrayIndexOutOfBounds," ${LOG_FILE} ; then
echo "arrayIndexOutOfBounds check failed"
ret_code=1
fi
if grep "syntaxError" ${LOG_FILE} | grep -v "is invalid C code" ; then
echo "syntaxError check failed"
ret_code=1
fi
if grep "memleak," ${LOG_FILE} ; then
echo "memleak check failed"
ret_code=1
fi
if grep "eraseDereference" ${LOG_FILE} ; then
echo "eraseDereference check failed"
ret_code=1
fi
if grep "memsetClass," ${LOG_FILE} ; then
echo "memsetClass check failed"
ret_code=1
fi
if grep "uninitvar," ${LOG_FILE} ; then
echo "uninitvar check failed"
ret_code=1
fi
if grep "uninitdata," ${LOG_FILE} ; then
echo "uninitdata check failed"
ret_code=1
fi
if grep "va_list_usedBeforeStarted" ${LOG_FILE} ; then
echo "va_list_usedBeforeStarted check failed"
ret_code=1
fi
if grep "duplInheritedMember" ${LOG_FILE} ; then
echo "duplInheritedMember check failed"
ret_code=1
fi
if grep "terminateStrncpy" ${LOG_FILE} ; then
echo "terminateStrncpy check failed"
ret_code=1
fi
if grep "operatorEqVarError" ${LOG_FILE} ; then
echo "operatorEqVarError check failed"
ret_code=1
fi
if grep "uselessAssignmentPtrArg" ${LOG_FILE} ; then
echo "uselessAssignmentPtrArg check failed"
ret_code=1
fi
if grep "bufferNotZeroTerminated" ${LOG_FILE} ; then
echo "bufferNotZeroTerminated check failed"
ret_code=1
fi
if grep "sizeofDivisionMemfunc" ${LOG_FILE} ; then
echo "sizeofDivisionMemfunc check failed"
ret_code=1
fi
if grep "selfAssignment" ${LOG_FILE} ; then
echo "selfAssignment check failed"
ret_code=1
fi
if grep "invalidPrintfArgType_sint" ${LOG_FILE} ; then
echo "invalidPrintfArgType_sint check failed"
ret_code=1
fi
if grep "redundantAssignInSwitch" ${LOG_FILE} ; then
echo "redundantAssignInSwitch check failed"
ret_code=1
fi
if grep "publicAllocationError" ${LOG_FILE} ; then
echo "publicAllocationError check failed"
ret_code=1
fi
if grep "invalidScanfArgType_int" ${LOG_FILE} ; then
echo "invalidScanfArgType_int check failed"
ret_code=1
fi
if grep "invalidscanf," ${LOG_FILE} ; then
echo "invalidscanf check failed"
ret_code=1
fi
if grep "moduloAlwaysTrueFalse" ${LOG_FILE} ; then
echo "moduloAlwaysTrueFalse check failed"
ret_code=1
fi
if grep "charLiteralWithCharPtrCompare" ${LOG_FILE} ; then
echo "charLiteralWithCharPtrCompare check failed"
ret_code=1
fi
if grep "noConstructor" ${LOG_FILE} ; then
echo "noConstructor check failed"
ret_code=1
fi
if grep "noExplicitConstructor" ${LOG_FILE} ; then
echo "noExplicitConstructor check failed"
ret_code=1
fi
if grep "noCopyConstructor" ${LOG_FILE} ; then
echo "noCopyConstructor check failed"
ret_code=1
fi
if grep "passedByValue" ${LOG_FILE} ; then
echo "passedByValue check failed"
ret_code=1
fi
if grep "postfixOperator" ${LOG_FILE} ; then
echo "postfixOperator check failed"
ret_code=1
fi
if grep "redundantCopy" ${LOG_FILE} ; then
echo "redundantCopy check failed"
ret_code=1
fi
if grep "stlIfStrFind" ${LOG_FILE} ; then
echo "stlIfStrFind check failed"
ret_code=1
fi
if grep "functionStatic" ${LOG_FILE} ; then
echo "functionStatic check failed"
ret_code=1
fi
if grep "knownConditionTrueFalse" ${LOG_FILE} ; then
echo "knownConditionTrueFalse check failed"
ret_code=1
fi
if grep "arrayIndexThenCheck" ${LOG_FILE} ; then
echo "arrayIndexThenCheck check failed"
ret_code=1
fi
if grep "unusedPrivateFunction" ${LOG_FILE} ; then
echo "unusedPrivateFunction check failed"
ret_code=1
fi
if grep "redundantCondition" ${LOG_FILE} ; then
echo "redundantCondition check failed"
ret_code=1
fi
if grep "unusedStructMember" ${LOG_FILE} ; then
echo "unusedStructMember check failed"
ret_code=1
fi
if grep "multiCondition" ${LOG_FILE} ; then
echo "multiCondition check failed"
ret_code=1
fi
if grep "duplicateExpression" ${LOG_FILE} ; then
echo "duplicateExpression check failed"
ret_code=1
fi
if grep "operatorEq" ${LOG_FILE} ; then
echo "operatorEq check failed"
ret_code=1
fi
if grep "truncLongCastAssignment" ${LOG_FILE} ; then
echo "truncLongCastAssignment check failed"
ret_code=1
fi
if grep "exceptRethrowCopy" ${LOG_FILE} ; then
echo "exceptRethrowCopy check failed"
ret_code=1
fi
if grep "unusedVariable" ${LOG_FILE} ; then
echo "unusedVariable check failed"
ret_code=1
fi
if grep "unsafeClassCanLeak" ${LOG_FILE} ; then
echo "unsafeClassCanLeak check failed"
ret_code=1
fi
if grep "unsignedLessThanZero" ${LOG_FILE} ; then
echo "unsignedLessThanZero check failed"
ret_code=1
fi
if grep "unpreciseMathCall" ${LOG_FILE} ; then
echo "unpreciseMathCall check failed"
ret_code=1
fi
if grep "unreachableCode" ${LOG_FILE} ; then
echo "unreachableCode check failed"
ret_code=1
fi
if grep "clarifyCondition" ${LOG_FILE} ; then
echo "clarifyCondition check failed"
ret_code=1
fi
if grep "redundantIfRemove" ${LOG_FILE} ; then
echo "redundantIfRemove check failed"
ret_code=1
fi
if grep "unassignedVariable" ${LOG_FILE} ; then
echo "unassignedVariable check failed"
ret_code=1
fi
if grep "redundantAssignment" ${LOG_FILE} ; then
echo "redundantAssignment check failed"
ret_code=1
fi
if grep "unreadVariable" ${LOG_FILE} ; then
echo "unreadVariable check failed"
ret_code=1
fi
if grep "AssignmentAddressToInteger" ${LOG_FILE} ; then
echo "AssignmentAddressToInteger check failed"
ret_code=1
fi
# Check any remaining errors
if grep "error," ${LOG_FILE} | grep -v "uninitvar" | \
grep -v "memleak," | grep -v "memleakOnRealloc" | \
grep -v "is invalid C code" ; then
echo "Errors check failed"
ret_code=1
fi
# Check any remaining warnings
if grep "warning," ${LOG_FILE}; then
echo "Warnings check failed"
ret_code=1
fi
if [ ${ret_code} = 0 ]; then
echo "cppcheck succeeded"
fi
exit ${ret_code}