8000 TST: add cppcheck to CI · numpy/numpy@940ac36 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 940ac36

Browse files
committed
TST: add cppcheck to CI
* add open source cppcheck analysis to Azure CI; the results of the static analysis are parsed using grep with success based on return codes indicating absence of various issues in the code base * there is still room to expand the issues we parse for--initially limited in scope to a few select static analysis issues, for which the code has been adjusted accordingly in this PR
1 parent 9cc9f01 commit 940ac36

File tree

7 files changed

+64
-11
lines changed

7 files changed

+64
-11
lines changed

azure-pipelines.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
# two C compilers, but with homebrew looks like we're
3434
# now stuck getting the full gcc toolchain instead of
3535
# just pulling in gfortran
36-
- script: brew install gcc
37-
displayName: 'make gfortran available on mac os vm'
36+
- script: brew install gcc cppcheck
37+
displayName: 'Install gfortran and cppcheck'
3838
- script: python -m pip install --upgrade pip setuptools wheel
3939
displayName: 'Install tools'
4040
- script: python -m pip install cython nose pytz pytest pickle5
@@ -55,6 +55,12 @@ jobs:
5555
ATLAS: None
5656
ACCELERATE: None
5757
CC: /usr/bin/clang
58+
- script: cppcheck --suppressions-list=tools/cppcheck_suppressions.txt --enable=all --xml -inumpy/linalg/lapack_lite -itools/swig . >& cppcheck_results.txt
59+
displayName: 'Run cppcheck static analysis on C files'
60+
# the grep checks for cppcheck issues below parse out xml error id tags
61+
# in the future, we may prefer to use an xml parser instead of grep
62+
- script: /bin/bash -c "! grep 'syntaxError' cppcheck_results.txt"
63+
displayName: 'Parse cppcheck results for syntax errors'
5864
- script: python runtests.py --mode=full -- -rsx --junitxml=junit/test-results.xml
5965
displayName: 'Run Full NumPy Test Suite'
6066
- task: PublishTestResults@2

numpy/core/src/multiarray/arrayobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ _void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op)
11281128

11291129
op = (cmp_op == Py_EQ ? n_ops.logical_and : n_ops.logical_or);
11301130
while (PyDict_Next(PyArray_DESCR(self)->fields, &pos, &key, &value)) {
1131-
if NPY_TITLE_KEY(key, value) {
1131+
if (NPY_TITLE_KEY(key, value)) {
11321132
continue;
11331133
}
11341134
a = array_subscript_asarray(self, key);

numpy/core/src/multiarray/descriptor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ _arraydescr_isnative(PyArray_Descr *self)
19681968
int offset;
19691969
Py_ssize_t pos = 0;
19701970
while (PyDict_Next(self->fields, &pos, &key, &value)) {
1971-
if NPY_TITLE_KEY(key, value) {
1971+
if (NPY_TITLE_KEY(key, value)) {
19721972
continue;
19731973
}
19741974
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {
@@ -2460,7 +2460,7 @@ _descr_find_object(PyArray_Descr *self)
24602460
Py_ssize_t pos = 0;
24612461

24622462
while (PyDict_Next(self->fields, &pos, &key, &value)) {
2463-
if NPY_TITLE_KEY(key, value) {
2463+
if (NPY_TITLE_KEY(key, value)) {
24642464
continue;
24652465
}
24662466
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {
@@ -2982,7 +2982,7 @@ PyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)
29822982
newfields = PyDict_New();
29832983
/* make new dictionary with replaced PyArray_Descr Objects */
29842984
while (PyDict_Next(self->fields, &pos, &key, &value)) {
2985-
if NPY_TITLE_KEY(key, value) {
2985+
if (NPY_TITLE_KEY(key, value)) {
29862986
continue;
29872987
}
29882988
if (!PyUString_Check(key) || !PyTuple_Check(value) ||

numpy/core/src/multiarray/methods.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype,
14201420
int offset;
14211421
Py_ssize_t pos = 0;
14221422
while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
1423-
if NPY_TITLE_KEY(key, value) {
1423+
if (NPY_TITLE_KEY(key, value)) {
14241424
continue;
14251425
}
14261426
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,

numpy/core/src/multiarray/refcount.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ PyArray_Item_INCREF(char *data, PyArray_Descr *descr)
4141
Py_ssize_t pos = 0;
4242

4343
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
44-
if NPY_TITLE_KEY(key, value) {
44+
if (NPY_TITLE_KEY(key, value)) {
4545
continue;
4646
}
4747
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
@@ -77,7 +77,7 @@ PyArray_Item_XDECREF(char *data, PyArray_Descr *descr)
7777
Py_ssize_t pos = 0;
7878

7979
while (PyDict_Next(descr->fields, &pos, &key, &value)) {
80-
if NPY_TITLE_KEY(key, value) {
80+
if (NPY_TITLE_KEY(key, value)) {
8181
continue;
8282
}
8383
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset,
@@ -265,7 +265,7 @@ _fillobject(char *optr, PyObject *obj, PyArray_Descr *dtype)
265265
Py_ssize_t pos = 0;
266266

267267
while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
268-
if NPY_TITLE_KEY(key, value) {
268+
if (NPY_TITLE_KEY(key, value)) {
269269
continue;
270270
}
271271
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {

numpy/core/src/multiarray/shape.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ _putzero(char *optr, PyObject *zero, PyArray_Descr *dtype)
317317
int offset;
318318
Py_ssize_t pos = 0;
319319
while (PyDict_Next(dtype->fields, &pos, &key, &value)) {
320-
if NPY_TITLE_KEY(key, value) {
320+
if (NPY_TITLE_KEY(key, value)) {
321321
continue;
322322
}
323323
if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {

tools/cppcheck_suppressions.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// suppress all warnings related to C template files
2+
*:*.src
3+
4+
// ignore warnings about large numbers of #ifdef configs
5+
toomanyconfigs:*
6+
7+
// ignore variable scope warnings -- CPython dev team
8+
// also ignored these when using cppcheck
9+
variableScope:*
10+
11+
// ignore config style warnings (#define directives that
12+
// cppcheck doesn't like, but are probably fine)
13+
ConfigurationNotChecked:*
14+
15+
// we have some pointer casts that could perhaps be typed
16+
// slightly more conservatively
17+
invalidPointerCast:*
18+
19+
// false positives for variables that are never used
20+
unreadVariable:*
21+
22+
// we probably don't want to start removing unused struct
23+
// members
24+
unusedStructMember:*
25+
26+
// ignore all warnings for Cython generated random code
27+
*:numpy/random/mtrand/mtrand.c
28+
29+
// unused function (dead code) detection is not reliable yet
30+
// ignore for all files -- probably related to having Python
31+
// interaction on top of regular C code
32+
unusedFunction:*
33+
34+
// some redundant variable assignments do look ok
35+
// after manual inspection
36+
redundantAssignment:numpy/core/src/common/mem_overlap.c
37+
redundantAssignment:numpy/core/src/multiarray/calculation.c
38+
redundantAssignment:numpy/core/src/multiarray/common.c
39+
redundantAssignment:numpy/core/src/multiarray/convert_datatype.c
40+
redundantAssignment:numpy/core/src/multiarray/ctors.c
41+
redundantAssignment:numpy/core/src/multiarray/descriptor.c
< 5295 /td>42+
redundantAssignment:numpy/core/src/multiarray/item_selection.c
43+
redundantAssignment:numpy/core/src/multiarray/iterators.c
44+
redundantAssignment:numpy/core/src/multiarray/mapping.c
45+
redundantAssignment:numpy/core/src/multiarray/methods.c
46+
47+

0 commit comments

Comments
 (0)
0