cppcheck/addons/threadsafety.py
Sebastian 8a32a210f8
addons: Change shebang to use Python 3 instead of Python 2 (#2361)
Use Python 3 instead of Python 2 if addons are executed directly.
Running cert.py and misra.py against test/cfg/std.c.dump shows that
Python 3 needs only half the time compared to Python 2. I have tested
it repeatedly and the results are always the same. This is no surprise
at all. The memory footprint is very likely also significantly better
but i have not tested it.
2019-11-15 21:38:20 +01:00

36 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
#
# This script analyses Cppcheck dump files to locate threadsafety issues
# - warn about static local objects
#
import cppcheckdata
import sys
def reportError(token, severity, msg, id):
cppcheckdata.reportError(token, severity, msg, 'threadsafety', id)
def checkstatic(data):
for var in data.variables:
if var.isStatic and var.isLocal:
type = None
if var.isClass:
type = 'object'
else:
type = 'variable'
if var.isConst:
reportError(var.typeStartToken, 'warning', 'Local constant static ' + type + ' \'' + var.nameToken.str + '\', dangerous if it is initialized in parallel threads', 'threadsafety')
else:
reportError(var.typeStartToken, 'warning', 'Local static ' + type + ': ' + var.nameToken.str, 'threadsafety')
for arg in sys.argv[1:]:
if arg.startswith('-'):
continue
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
for cfg in data.configurations:
if len(data.configurations) > 1:
print('Checking ' + arg + ', config "' + cfg.name + '"...')
checkstatic(cfg)