cppcheck-py 2.9__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cppcheck/__init__.py +55 -0
- cppcheck/cppcheck-2.9.tar.gz +0 -0
- cppcheck/data/addons/__init__.py +0 -0
- cppcheck/data/addons/cppcheck.py +39 -0
- cppcheck/data/addons/cppcheckdata.py +1529 -0
- cppcheck/data/addons/findcasts.py +33 -0
- cppcheck/data/addons/misc.py +163 -0
- cppcheck/data/addons/misra.py +4728 -0
- cppcheck/data/addons/misra_9.py +513 -0
- cppcheck/data/addons/naming.py +91 -0
- cppcheck/data/addons/namingng.py +253 -0
- cppcheck/data/addons/runaddon.py +12 -0
- cppcheck/data/addons/threadsafety.py +39 -0
- cppcheck/data/addons/y2038.py +252 -0
- cppcheck/data/cfg/avr.cfg +431 -0
- cppcheck/data/cfg/bento4.cfg +142 -0
- cppcheck/data/cfg/boost.cfg +1268 -0
- cppcheck/data/cfg/bsd.cfg +546 -0
- cppcheck/data/cfg/cairo.cfg +88 -0
- cppcheck/data/cfg/cppcheck-lib.cfg +72 -0
- cppcheck/data/cfg/cppunit.cfg +48 -0
- cppcheck/data/cfg/daca.cfg +31 -0
- cppcheck/data/cfg/dpdk.cfg +11 -0
- cppcheck/data/cfg/embedded_sql.cfg +4 -0
- cppcheck/data/cfg/emscripten.cfg +7 -0
- cppcheck/data/cfg/ginac.cfg +12848 -0
- cppcheck/data/cfg/gnu.cfg +1626 -0
- cppcheck/data/cfg/googletest.cfg +60 -0
- cppcheck/data/cfg/gtk.cfg +20584 -0
- cppcheck/data/cfg/icu.cfg +6 -0
- cppcheck/data/cfg/kde.cfg +51 -0
- cppcheck/data/cfg/libcerror.cfg +128 -0
- cppcheck/data/cfg/libcurl.cfg +487 -0
- cppcheck/data/cfg/libsigc++.cfg +36 -0
- cppcheck/data/cfg/lua.cfg +316 -0
- cppcheck/data/cfg/mfc.cfg +256 -0
- cppcheck/data/cfg/microsoft_atl.cfg +40 -0
- cppcheck/data/cfg/microsoft_sal.cfg +491 -0
- cppcheck/data/cfg/microsoft_unittest.cfg +20 -0
- cppcheck/data/cfg/motif.cfg +318 -0
- cppcheck/data/cfg/nspr.cfg +38 -0
- cppcheck/data/cfg/ntl.cfg +6907 -0
- cppcheck/data/cfg/opencv2.cfg +132 -0
- cppcheck/data/cfg/opengl.cfg +580 -0
- cppcheck/data/cfg/openmp.cfg +157 -0
- cppcheck/data/cfg/openssl.cfg +174 -0
- cppcheck/data/cfg/pcre.cfg +165 -0
- cppcheck/data/cfg/posix.cfg +6252 -0
- cppcheck/data/cfg/python.cfg +674 -0
- cppcheck/data/cfg/qt.cfg +5255 -0
- cppcheck/data/cfg/ruby.cfg +142 -0
- cppcheck/data/cfg/sdl.cfg +354 -0
- cppcheck/data/cfg/sfml.cfg +301 -0
- cppcheck/data/cfg/sqlite3.cfg +1527 -0
- cppcheck/data/cfg/std.cfg +8716 -0
- cppcheck/data/cfg/tinyxml2.cfg +56 -0
- cppcheck/data/cfg/vcl.cfg +4 -0
- cppcheck/data/cfg/windows.cfg +17941 -0
- cppcheck/data/cfg/wxsqlite3.cfg +1955 -0
- cppcheck/data/cfg/wxsvg.cfg +16905 -0
- cppcheck/data/cfg/wxwidgets.cfg +16464 -0
- cppcheck/data/cfg/zlib.cfg +1450 -0
- cppcheck/data/cppcheck-htmlreport +986 -0
- cppcheck/data/cppcheck.exe +0 -0
- cppcheck/data/platforms/aix_ppc64.xml +17 -0
- cppcheck/data/platforms/arm32-wchar_t2.xml +17 -0
- cppcheck/data/platforms/arm32-wchar_t4.xml +17 -0
- cppcheck/data/platforms/arm64-wchar_t2.xml +17 -0
- cppcheck/data/platforms/arm64-wchar_t4.xml +17 -0
- cppcheck/data/platforms/avr8.xml +18 -0
- cppcheck/data/platforms/cray_sv1.xml +17 -0
- cppcheck/data/platforms/elbrus-e1cp.xml +18 -0
- cppcheck/data/platforms/mips32.xml +18 -0
- cppcheck/data/platforms/msp430_eabi_large_datamodel.xml +17 -0
- cppcheck/data/platforms/pic16.xml +18 -0
- cppcheck/data/platforms/pic8-enhanced.xml +18 -0
- cppcheck/data/platforms/pic8.xml +18 -0
- cppcheck/data/platforms/unix32-unsigned.xml +17 -0
- cppcheck/data/platforms/unix64-unsigned.xml +17 -0
- cppcheck_py-2.9.dist-info/METADATA +76 -0
- cppcheck_py-2.9.dist-info/RECORD +84 -0
- cppcheck_py-2.9.dist-info/WHEEL +5 -0
- cppcheck_py-2.9.dist-info/entry_points.txt +4 -0
- cppcheck_py-2.9.dist-info/licenses/LICENSE.md +191 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# Locate casts in the code
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
import cppcheck
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
@cppcheck.checker
|
|
10
|
+
def cast(cfg, data):
|
|
11
|
+
for token in cfg.tokenlist:
|
|
12
|
+
if token.str != '(' or not token.astOperand1 or token.astOperand2:
|
|
13
|
+
continue
|
|
14
|
+
|
|
15
|
+
# Is it a lambda?
|
|
16
|
+
if token.astOperand1.str == '{':
|
|
17
|
+
continue
|
|
18
|
+
|
|
19
|
+
# we probably have a cast.. if there is something inside the parentheses
|
|
20
|
+
# there is a cast. Otherwise this is a function call.
|
|
21
|
+
typetok = token.next
|
|
22
|
+
if not typetok.isName:
|
|
23
|
+
continue
|
|
24
|
+
|
|
25
|
+
# cast number => skip output
|
|
26
|
+
if token.astOperand1.isNumber:
|
|
27
|
+
continue
|
|
28
|
+
|
|
29
|
+
# void cast => often used to suppress compiler warnings
|
|
30
|
+
if typetok.str == 'void':
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
cppcheck.reportError(token, 'information', 'found a cast')
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# Misc: Uncategorized checks that might be moved to some better addon later
|
|
4
|
+
#
|
|
5
|
+
# Example usage of this addon (scan a sourcefile main.cpp)
|
|
6
|
+
# cppcheck --dump main.cpp
|
|
7
|
+
# python misc.py main.cpp.dump
|
|
8
|
+
|
|
9
|
+
import cppcheckdata
|
|
10
|
+
import sys
|
|
11
|
+
import re
|
|
12
|
+
|
|
13
|
+
DEBUG = ('-debug' in sys.argv)
|
|
14
|
+
VERIFY = ('-verify' in sys.argv)
|
|
15
|
+
VERIFY_EXPECTED = []
|
|
16
|
+
VERIFY_ACTUAL = []
|
|
17
|
+
|
|
18
|
+
def reportError(token, severity, msg, id):
|
|
19
|
+
if id == 'debug' and DEBUG == False:
|
|
20
|
+
return
|
|
21
|
+
if VERIFY:
|
|
22
|
+
VERIFY_ACTUAL.append(str(token.linenr) + ':' + id)
|
|
23
|
+
else:
|
|
24
|
+
cppcheckdata.reportError(token, severity, msg, 'misc', id)
|
|
25
|
+
|
|
26
|
+
def simpleMatch(token, pattern):
|
|
27
|
+
return cppcheckdata.simpleMatch(token, pattern)
|
|
28
|
+
|
|
29
|
+
# Get function arguments
|
|
30
|
+
def getArgumentsRecursive(tok, arguments):
|
|
31
|
+
if tok is None:
|
|
32
|
+
return
|
|
33
|
+
if tok.str == ',':
|
|
34
|
+
getArgumentsRecursive(tok.astOperand1, arguments)
|
|
35
|
+
getArgumentsRecursive(tok.astOperand2, arguments)
|
|
36
|
+
else:
|
|
37
|
+
arguments.append(tok)
|
|
38
|
+
|
|
39
|
+
def getArguments(ftok):
|
|
40
|
+
arguments = []
|
|
41
|
+
getArgumentsRecursive(ftok.astOperand2, arguments)
|
|
42
|
+
return arguments
|
|
43
|
+
|
|
44
|
+
def isStringLiteral(tokenString):
|
|
45
|
+
return tokenString.startswith('"')
|
|
46
|
+
|
|
47
|
+
# check data
|
|
48
|
+
def stringConcatInArrayInit(data):
|
|
49
|
+
# Get all string macros
|
|
50
|
+
stringMacros = []
|
|
51
|
+
for cfg in data.iterconfigurations():
|
|
52
|
+
for directive in cfg.directives:
|
|
53
|
+
res = re.match(r'#define[ ]+([A-Za-z0-9_]+)[ ]+".*', directive.str)
|
|
54
|
+
if res:
|
|
55
|
+
macroName = res.group(1)
|
|
56
|
+
if macroName not in stringMacros:
|
|
57
|
+
stringMacros.append(macroName)
|
|
58
|
+
|
|
59
|
+
# Check code
|
|
60
|
+
arrayInit = False
|
|
61
|
+
for i in range(len(data.rawTokens)):
|
|
62
|
+
if i < 2:
|
|
63
|
+
continue
|
|
64
|
+
tok1 = data.rawTokens[i-2].str
|
|
65
|
+
tok2 = data.rawTokens[i-1].str
|
|
66
|
+
tok3 = data.rawTokens[i-0].str
|
|
67
|
+
if tok3 == '}':
|
|
68
|
+
arrayInit = False
|
|
69
|
+
elif tok1 == ']' and tok2 == '=' and tok3 == '{':
|
|
70
|
+
arrayInit = True
|
|
71
|
+
elif arrayInit and (tok1 in [',', '{']):
|
|
72
|
+
isString2 = (isStringLiteral(tok2) or (tok2 in stringMacros))
|
|
73
|
+
isString3 = (isStringLiteral(tok3) or (tok3 in stringMacros))
|
|
74
|
+
if isString2 and isString3:
|
|
75
|
+
reportError(data.rawTokens[i], 'style', 'String concatenation in array initialization, missing comma?', 'stringConcatInArrayInit')
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def implicitlyVirtual(data):
|
|
79
|
+
for cfg in data.iterconfigurations():
|
|
80
|
+
for function in cfg.functions:
|
|
81
|
+
if function.isImplicitlyVirtual is None:
|
|
82
|
+
continue
|
|
83
|
+
if not function.isImplicitlyVirtual:
|
|
84
|
+
continue
|
|
85
|
+
reportError(function.tokenDef, 'style', 'Function \'' + function.name + '\' overrides base class function but is not marked with \'virtual\' keyword.', 'implicitlyVirtual')
|
|
86
|
+
|
|
87
|
+
def ellipsisStructArg(data):
|
|
88
|
+
for cfg in data.iterconfigurations():
|
|
89
|
+
for tok in cfg.tokenlist:
|
|
90
|
+
if tok.str != '(':
|
|
91
|
+
continue
|
|
92
|
+
if tok.astOperand1 is None or tok.astOperand2 is None:
|
|
93
|
+
continue
|
|
94
|
+
if tok.astOperand2.str != ',':
|
|
95
|
+
continue
|
|
96
|
+
if tok.scope.type in ['Global', 'Class']:
|
|
97
|
+
continue
|
|
98
|
+
if tok.astOperand1.function is None:
|
|
99
|
+
continue
|
|
100
|
+
for argnr, argvar in tok.astOperand1.function.argument.items():
|
|
101
|
+
if argnr < 1:
|
|
102
|
+
continue
|
|
103
|
+
if not simpleMatch(argvar.typeStartToken, '...'):
|
|
104
|
+
continue
|
|
105
|
+
callArgs = getArguments(tok)
|
|
106
|
+
for i in range(argnr-1, len(callArgs)):
|
|
107
|
+
valueType = callArgs[i].valueType
|
|
108
|
+
if valueType is None:
|
|
109
|
+
argStart = callArgs[i].previous
|
|
110
|
+
while argStart.str != ',':
|
|
111
|
+
if argStart.str == ')':
|
|
112
|
+
argStart = argStart.link
|
|
113
|
+
argStart = argStart.previous
|
|
114
|
+
argEnd = callArgs[i]
|
|
115
|
+
while argEnd.str != ',' and argEnd.str != ')':
|
|
116
|
+
if argEnd.str == '(':
|
|
117
|
+
argEnd = argEnd.link
|
|
118
|
+
argEnd = argEnd.next
|
|
119
|
+
expression = ''
|
|
120
|
+
argStart = argStart.next
|
|
121
|
+
while argStart != argEnd:
|
|
122
|
+
expression = expression + argStart.str
|
|
123
|
+
argStart = argStart.next
|
|
124
|
+
reportError(tok, 'debug', 'Bailout, unknown argument type for argument \'' + expression + '\'.', 'debug')
|
|
125
|
+
continue
|
|
126
|
+
if valueType.pointer > 0:
|
|
127
|
+
continue
|
|
128
|
+
if valueType.type != 'record' and valueType.type != 'container':
|
|
129
|
+
continue
|
|
130
|
+
reportError(tok, 'style', 'Passing record to ellipsis function \'' + tok.astOperand1.function.name + '\'.', 'ellipsisStructArg')
|
|
131
|
+
break
|
|
132
|
+
|
|
133
|
+
for arg in sys.argv[1:]:
|
|
134
|
+
if arg in ['-debug', '-verify', '--cli']:
|
|
135
|
+
continue
|
|
136
|
+
|
|
137
|
+
print("Checking %s..." % arg)
|
|
138
|
+
data = cppcheckdata.CppcheckData(arg)
|
|
139
|
+
|
|
140
|
+
if VERIFY:
|
|
141
|
+
VERIFY_ACTUAL = []
|
|
142
|
+
VERIFY_EXPECTED = []
|
|
143
|
+
for tok in data.rawTokens:
|
|
144
|
+
if tok.str.startswith('//'):
|
|
145
|
+
for word in tok.str[2:].split(' '):
|
|
146
|
+
if word in ['stringConcatInArrayInit', 'implicitlyVirtual', 'ellipsisStructArg']:
|
|
147
|
+
VERIFY_EXPECTED.append(str(tok.linenr) + ':' + word)
|
|
148
|
+
|
|
149
|
+
stringConcatInArrayInit(data)
|
|
150
|
+
implicitlyVirtual(data)
|
|
151
|
+
ellipsisStructArg(data)
|
|
152
|
+
|
|
153
|
+
if VERIFY:
|
|
154
|
+
for expected in VERIFY_EXPECTED:
|
|
155
|
+
if expected not in VERIFY_ACTUAL:
|
|
156
|
+
print('Expected but not seen: ' + expected)
|
|
157
|
+
sys.exit(1)
|
|
158
|
+
for actual in VERIFY_ACTUAL:
|
|
159
|
+
if actual not in VERIFY_EXPECTED:
|
|
160
|
+
print('Not expected: ' + actual)
|
|
161
|
+
sys.exit(1)
|
|
162
|
+
|
|
163
|
+
sys.exit(cppcheckdata.EXIT_CODE)
|