Skip to content

Commit 4ad09f1

Browse files
committed
Fixed #10480 (FP: misra-c2012-10.4 (char))
1 parent 255dc04 commit 4ad09f1

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

addons/misra.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,11 @@ def getEssentialTypeCategory(expr):
443443
return expr.valueType.sign
444444
if expr.valueType and expr.valueType.typeScope and expr.valueType.typeScope.className:
445445
return "enum<" + expr.valueType.typeScope.className + ">"
446-
if expr.variable:
447-
typeToken = expr.variable.typeStartToken
446+
vartok = expr
447+
while simpleMatch(vartok, '[') or (vartok and vartok.str == '*' and vartok.astOperand2 is None):
448+
vartok = vartok.astOperand1
449+
if vartok and vartok.variable:
450+
typeToken = vartok.variable.typeStartToken
448451
while typeToken and typeToken.isName:
449452
if typeToken.str == 'char' and not typeToken.isSigned and not typeToken.isUnsigned:
450453
return 'char'

addons/test/misra/misra-test-avr8.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// To test:
22
// ~/cppcheck/cppcheck --addon=misra --platform=avr8 misra-test-avr8.c
33

4+
static void misra_10_4(void)
5+
{
6+
// #10480
7+
char buf[1] = {'f'};
8+
const char c = '0';
9+
signed int x = buf[0] - c;
10+
}
11+
412
static void misra_12_2(void) {
513
a = (((uint64_t)0xFF) << 32);
614
}

0 commit comments

Comments
 (0)