threadsafety.py: warn for local static non-class variables also

This commit is contained in:
Daniel Marjamäki 2018-03-14 11:55:01 +01:00
parent 814828f436
commit b8d0da31de
2 changed files with 13 additions and 2 deletions

View File

@ -345,6 +345,7 @@ class Variable:
isArgument Is this variable a function argument?
isArray Is this variable an array?
isClass Is this variable a class or struct?
isConst Is this variable a const variable?
isExtern Is this variable an extern variable?
isLocal Is this variable a local variable?
isPointer Is this variable a pointer
@ -362,6 +363,7 @@ class Variable:
isArgument = False
isArray = False
isClass = False
isConst = False
isExtern = False
isLocal = False
isPointer = False
@ -379,6 +381,7 @@ class Variable:
self.isArgument = element.get('isArgument') == 'true'
self.isArray = element.get('isArray') == 'true'
self.isClass = element.get('isClass') == 'true'
self.isConst = element.get('isConst') == 'true'
self.isExtern = element.get('isExtern') == 'true'
self.isLocal = element.get('isLocal') == 'true'
self.isPointer = element.get('isPointer') == 'true'

View File

@ -15,8 +15,16 @@ def reportError(token, severity, msg, id):
def checkstatic(data):
for var in data.variables:
if var.isStatic and var.isLocal and var.isClass:
reportError(var.typeStartToken, 'warning', ('Local static object: ' + var.nameToken.str), 'threadsafety')
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 parallell threads', 'threadsafety')
else:
reportError(var.typeStartToken, 'warning', 'Local static ' + type + ': ' + var.nameToken.str, 'threadsafety')
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')