From 8f21ba91e3abd5c59e19c6022d33288c41be0d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 12 Apr 2018 20:23:50 +0200 Subject: [PATCH] cert.py: Fix FP --- addons/cert.py | 5 +++-- addons/cppcheckdata.py | 5 +++++ addons/test/cert-test.c | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/cert.py b/addons/cert.py index b4ef5ce28..4efcaa605 100755 --- a/addons/cert.py +++ b/addons/cert.py @@ -113,14 +113,15 @@ def exp05(data): continue if not argvar.isPointer: continue + if (argvar.constness % 2) == 1: # data is const + continue argtok = arguments[argnr - 1] if not argtok.valueType: continue if argtok.valueType.pointer == 0: continue - const1 = argvar.isConst const2 = arguments[argnr - 1].valueType.constness - if (const1 % 2) < (const2 % 2): + if (const2 % 2) == 1: reportError(token, 'style', "Attempt to cast away const", 'cert-EXP05-C') diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index d2cf28b78..58f823b91 100755 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -351,6 +351,7 @@ class Variable: isPointer Is this variable a pointer isReference Is this variable a reference isStatic Is this variable static? + constness Variable constness (same encoding as ValueType::constness) """ Id = None @@ -369,6 +370,7 @@ class Variable: isPointer = False isReference = False isStatic = False + constness = 0 def __init__(self, element): self.Id = element.get('id') @@ -387,6 +389,9 @@ class Variable: self.isPointer = element.get('isPointer') == 'true' self.isReference = element.get('isReference') == 'true' self.isStatic = element.get('isStatic') == 'true' + self.constness = element.get('constness') + if self.constness: + self.constness = int(self.constness) def setId(self, IdMap): self.nameToken = IdMap[self.nameTokenId] diff --git a/addons/test/cert-test.c b/addons/test/cert-test.c index 3eea3ee1b..0698e4389 100644 --- a/addons/test/cert-test.c +++ b/addons/test/cert-test.c @@ -26,6 +26,11 @@ void exp05() dostuff(data); // cert-EXP05-C } +void print(const char *p); +void exp05_fp() { + print("hello"); +} + void exp42() { struct S s1 = {1,2};