From b8d0da31de71f5591fd31a1e8a7f26f973a6a767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 14 Mar 2018 11:55:01 +0100 Subject: [PATCH] threadsafety.py: warn for local static non-class variables also --- addons/cppcheckdata.py | 3 +++ addons/threadsafety.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index ceeee8b19..245ea8938 100644 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -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' diff --git a/addons/threadsafety.py b/addons/threadsafety.py index 92b109252..07cd5b1ec 100644 --- a/addons/threadsafety.py +++ b/addons/threadsafety.py @@ -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 + '...')