misra.py: Fix 7.4 false positive (#2883)

Fix false positives for the function calls with "const pointer to const
value" arguments: https://trac.cppcheck.net/ticket/9967.

The variable.valueType.constness have same encoding as encoding as
ValueType::constness in Cppcheck.
This commit is contained in:
Georgy Komarov 2020-11-05 10:13:23 +03:00 committed by GitHub
parent c6036f8704
commit 6f7f508967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -1398,7 +1398,7 @@ class MisraChecker:
# is constant.
def reportErrorIfVariableIsNotConst(variable, stringLiteral):
if variable.valueType:
if variable.valueType.constness != 1:
if (variable.valueType.constness % 2) != 1:
self.reportError(stringLiteral, 7, 4)
for token in data.tokenlist:

View File

@ -239,6 +239,7 @@ char *misra_7_4_return_non_const (void) { return 1 + "return_non_const"; } // 7.
const char *misra_7_4_return_const (void) { return 1 + "return_const"; } // 18.4
void misra_7_4_const_call(int a, const char* b) { } // 2.7
void misra_7_4_const_ptr_call(int a, const char const* b) { } // 2.7
void misra_7_4_call(int a, char* b) { } // 2.7
void misra_7_4()
@ -253,6 +254,7 @@ void misra_7_4()
wchar_t *h = "text_h"; // 7.4
misra_7_4_const_call(1, ("text_const_call"));
misra_7_4_const_ptr_call(1, ("text_const_call"));
misra_7_4_call(1, "text_call"); // 7.4 11.8
}