Skip to content

Commit 1284470

Browse files
authored
Fix #9488: MISRA addon: False positive for rule 10.6 in test for rule 10.1 (#5598)
1 parent 915b4b6 commit 1284470

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

addons/misra.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,9 @@ def misra_10_6(self, data):
23872387
e = getEssentialType(token.astOperand2)
23882388
if not e:
23892389
continue
2390+
if e == "char" and vt1.type == "int":
2391+
# When arithmetic operations are performed on char values, they are usually promoted to int
2392+
continue
23902393
lhsbits = vt1.bits if vt1.bits else bitsOfEssentialType(vt1.type)
23912394
if lhsbits > bitsOfEssentialType(e):
23922395
self.reportError(token, 10, 6)

addons/test/misra/misra-test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ static void misra_10_6(u8 x, char c1, char c2) {
749749
u16 y1 = x+x; // 10.6
750750
u16 y2 = (0x100u - 0x80u); // rhs is not a composite expression because it's a constant expression
751751
u16 z = ~u8 x ;//10.6
752-
s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488
752+
s32 i = c1 - c2; // 10.3
753753
struct misra_10_6_s s;
754754
s.a = x & 1U; // no-warning (#10487)
755755
}

0 commit comments

Comments
 (0)