clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name _ctest.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-output=html -analyzer-checker=python -analyzer-disable-checker=deadcode -analyzer-config prune-paths=true,suppress-c++-stdlib=true,suppress-null-return-paths=false,crosscheck-with-z3=true,model-path=/opt/pyrefcon/lib/pyrefcon/models/models -analyzer-config experimental-enable-naive-ctu-analysis=true,ctu-dir=/tmp/pyrefcon/scipy/csa-scan,ctu-index-name=/tmp/pyrefcon/scipy/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/scipy/csa-scan/invocations.yaml,display-ctu-progress=false -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/pyrefcon/scipy -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -D NDEBUG -D _FORTIFY_SOURCE=2 -D NPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION -D NO_ATLAS_INFO=1 -D HAVE_CBLAS -I /usr/lib/python3/dist-packages/numpy/core/include -I /usr/lib/python3/dist-packages/numpy/core/include -internal-isystem /opt/pyrefcon/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-result -Wsign-compare -Wall -Wformat -Werror=format-security -Wformat -Werror=format-security -Wdate-time -fdebug-compilation-dir=/tmp/pyrefcon/scipy -ferror-limit 19 -fwrapv -pthread -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/scipy/csa-scan/reports -x c scipy/ndimage/src/_ctest.c
1 | #include <Python.h> |
2 | #include <numpy/npy_common.h> |
3 | |
4 | |
5 | static void |
6 | _destructor(PyObject *obj) |
7 | { |
8 | void *callback_data = PyCapsule_GetContext(obj); |
9 | PyMem_Free(callback_data); |
10 | } |
11 | |
12 | |
13 | static int |
14 | _filter1d(double *input_line, npy_intp input_length, double *output_line, |
15 | npy_intp output_length, void *callback_data) |
16 | { |
17 | npy_intp i, j; |
18 | npy_intp filter_size = *(npy_intp *)callback_data; |
19 | |
20 | for (i = 0; i < output_length; i++) { |
21 | output_line[i] = 0; |
22 | for (j = 0; j < filter_size; j++) { |
23 | output_line[i] += input_line[i+j]; |
24 | } |
25 | output_line[i] /= filter_size; |
26 | } |
27 | return 1; |
28 | } |
29 | |
30 | |
31 | static PyObject * |
32 | py_filter1d(PyObject *obj, PyObject *args) |
33 | { |
34 | npy_intp *callback_data = NULL; |
35 | PyObject *capsule = NULL; |
36 | |
37 | callback_data = PyMem_Malloc(sizeof(npy_intp)); |
38 | if (!callback_data) { |
39 | PyErr_NoMemory(); |
40 | goto error; |
41 | } |
42 | if (!PyArg_ParseTuple(args, "n", callback_data)) goto error; |
43 | |
44 | capsule = PyCapsule_New(_filter1d, NULL, _destructor); |
45 | if (!capsule) goto error; |
46 | if (PyCapsule_SetContext(capsule, callback_data) != 0) { |
47 | Py_DECREF(capsule); |
48 | goto error; |
49 | } |
50 | return capsule; |
51 | error: |
52 | PyMem_Free(callback_data); |
53 | return NULL; |
54 | } |
55 | |
56 | |
57 | static int |
58 | _filter2d(double *buffer, npy_intp filter_size, double *res, |
59 | void *callback_data) |
60 | { |
61 | npy_intp i; |
62 | double *weights = (double *)callback_data; |
63 | |
64 | *res = 0; |
65 | for (i = 0; i < filter_size; i++) { |
66 | *res += weights[i]*buffer[i]; |
67 | } |
68 | return 1; |
69 | } |
70 | |
71 | |
72 | static PyObject * |
73 | py_filter2d(PyObject *obj, PyObject *args) |
74 | { |
75 | Py_ssize_t i, size; |
76 | double *callback_data = NULL; |
77 | PyObject *seq = NULL, *item = NULL, *capsule = NULL; |
78 | |
79 | if (!PyArg_ParseTuple(args, "O", &seq)) goto error; |
| 1 | Assuming the condition is false | |
|
| |
80 | |
81 | size = PySequence_Length(seq); |
82 | if (size == -1) goto error; |
| 3 | | Assuming the condition is false | |
|
| |
83 | callback_data = PyMem_Malloc(size*sizeof(double)); |
84 | if (!callback_data) { |
| 5 | | Assuming 'callback_data' is non-null | |
|
| |
85 | PyErr_NoMemory(); |
86 | goto error; |
87 | } |
88 | |
89 | for (i = 0; i < size; i++) { |
| 7 | | Assuming 'i' is < 'size' | |
|
| 8 | | Loop condition is true. Entering loop body | |
|
90 | item = PySequence_GetItem(seq, i); |
| 9 | | Calling 'PySequence_GetItem' | |
|
| 11 | | Returning from 'PySequence_GetItem' | |
|
| 17 | | PyObject ownership leak with reference count of 1 |
|
91 | if (!item) { |
| 12 | | Assuming 'item' is non-null | |
|
| |
92 | PyErr_SetString(PyExc_IndexError, "failed to get item"); |
93 | goto error; |
94 | } |
95 | callback_data[i] = PyFloat_AsDouble(item); |
96 | if (PyErr_Occurred()) goto error; |
| 14 | | Assuming the condition is true | |
|
| |
| 16 | | Control jumps to line 107 | |
|
97 | } |
98 | |
99 | capsule = PyCapsule_New(_filter2d, NULL, _destructor); |
100 | if (!capsule) goto error; |
101 | if (PyCapsule_SetContext(capsule, callback_data) != 0) { |
102 | Py_DECREF(capsule); |
103 | goto error; |
104 | } |
105 | return capsule; |
106 | error: |
107 | PyMem_Free(callback_data); |
108 | return NULL; |
109 | } |
110 | |
111 | |
112 | static int |
113 | _transform(npy_intp *output_coordinates, double *input_coordinates, |
114 | npy_intp output_rank, npy_intp input_rank, void *callback_data) |
115 | { |
116 | npy_intp i; |
117 | double shift = *(double *)callback_data; |
118 | |
119 | for (i = 0; i < input_rank; i++) { |
120 | input_coordinates[i] = output_coordinates[i] - shift; |
121 | } |
122 | return 1; |
123 | } |
124 | |
125 | |
126 | static PyObject * |
127 | py_transform(PyObject *obj, PyObject *args) |
128 | { |
129 | double *callback_data = PyMem_Malloc(sizeof(double)); |
130 | PyObject *capsule = NULL; |
131 | |
132 | if (!callback_data) { |
133 | PyErr_NoMemory(); |
134 | goto error; |
135 | } |
136 | if (!PyArg_ParseTuple(args, "d", callback_data)) goto error; |
137 | |
138 | capsule = PyCapsule_New(_transform, NULL, _destructor); |
139 | if (!capsule) goto error; |
140 | if (PyCapsule_SetContext(capsule, callback_data) != 0) { |
141 | Py_DECREF(capsule); |
142 | goto error; |
143 | } |
144 | return capsule; |
145 | error: |
146 | PyMem_Free(callback_data); |
147 | return NULL; |
148 | } |
149 | |
150 | |
151 | static PyMethodDef _CTestMethods[] = { |
152 | {"transform", (PyCFunction)py_transform, METH_VARARGS, ""}, |
153 | {"filter1d", (PyCFunction)py_filter1d, METH_VARARGS, ""}, |
154 | {"filter2d", (PyCFunction)py_filter2d, METH_VARARGS, ""}, |
155 | {NULL, NULL, 0, NULL} |
156 | }; |
157 | |
158 | |
159 | |
160 | static struct PyModuleDef _ctest = { |
161 | PyModuleDef_HEAD_INIT, |
162 | "_ctest", |
163 | NULL, |
164 | -1, |
165 | _CTestMethods, |
166 | NULL, |
167 | NULL, |
168 | NULL, |
169 | NULL |
170 | }; |
171 | |
172 | |
173 | PyObject *PyInit__ctest(void) |
174 | { |
175 | return PyModule_Create(&_ctest); |
176 | } |