2019-11-15 21:38:20 +01:00
#!/usr/bin/env python3
2015-06-20 22:06:22 +02:00
#
# This script analyses Cppcheck dump files to locate threadsafety issues
# - warn about static local objects
#
2019-12-30 17:30:17 +01:00
import cppcheckdata
2015-06-20 22:06:22 +02:00
import sys
2017-08-15 21:44:21 +02:00
def reportError ( token , severity , msg , id ) :
2019-04-14 08:54:53 +02:00
cppcheckdata . reportError ( token , severity , msg , ' threadsafety ' , id )
2015-08-21 10:55:19 +02:00
2015-06-20 22:06:22 +02:00
def checkstatic ( data ) :
2015-08-21 10:55:19 +02:00
for var in data . variables :
2018-03-14 11:55:01 +01:00
if var . isStatic and var . isLocal :
type = None
if var . isClass :
type = ' object '
else :
type = ' variable '
if var . isConst :
2018-05-14 13:11:45 +02:00
reportError ( var . typeStartToken , ' warning ' , ' Local constant static ' + type + ' \' ' + var . nameToken . str + ' \' , dangerous if it is initialized in parallel threads ' , ' threadsafety ' )
2018-03-14 11:55:01 +01:00
else :
reportError ( var . typeStartToken , ' warning ' , ' Local static ' + type + ' : ' + var . nameToken . str , ' threadsafety ' )
2015-06-20 22:06:22 +02:00
for arg in sys . argv [ 1 : ] :
2019-04-10 21:06:40 +02:00
if arg . startswith ( ' - ' ) :
continue
2019-12-27 08:50:56 +01:00
print ( ' Checking %s ... ' % arg )
data = cppcheckdata . CppcheckData ( arg )
for cfg in data . iterconfigurations ( ) :
print ( ' Checking %s , config %s ... ' % ( arg , cfg . name ) )
2015-12-14 09:37:26 +01:00
checkstatic ( cfg )