Fixed #10480 (FP: misra-c2012-10.4 (char))

This commit is contained in:
Daniel Marjamäki 2021-09-22 13:02:11 +02:00
parent 255dc0484a
commit 4ad09f181a
2 changed files with 13 additions and 2 deletions

View File

@ -443,8 +443,11 @@ def getEssentialTypeCategory(expr):
return expr.valueType.sign return expr.valueType.sign
if expr.valueType and expr.valueType.typeScope and expr.valueType.typeScope.className: if expr.valueType and expr.valueType.typeScope and expr.valueType.typeScope.className:
return "enum<" + expr.valueType.typeScope.className + ">" return "enum<" + expr.valueType.typeScope.className + ">"
if expr.variable: vartok = expr
typeToken = expr.variable.typeStartToken while simpleMatch(vartok, '[') or (vartok and vartok.str == '*' and vartok.astOperand2 is None):
vartok = vartok.astOperand1
if vartok and vartok.variable:
typeToken = vartok.variable.typeStartToken
while typeToken and typeToken.isName: while typeToken and typeToken.isName:
if typeToken.str == 'char' and not typeToken.isSigned and not typeToken.isUnsigned: if typeToken.str == 'char' and not typeToken.isSigned and not typeToken.isUnsigned:
return 'char' return 'char'

View File

@ -1,6 +1,14 @@
// To test: // To test:
// ~/cppcheck/cppcheck --addon=misra --platform=avr8 misra-test-avr8.c // ~/cppcheck/cppcheck --addon=misra --platform=avr8 misra-test-avr8.c
static void misra_10_4(void)
{
// #10480
char buf[1] = {'f'};
const char c = '0';
signed int x = buf[0] - c;
}
static void misra_12_2(void) { static void misra_12_2(void) {
a = (((uint64_t)0xFF) << 32); a = (((uint64_t)0xFF) << 32);
} }