Skip to content

Commit

Permalink
Fix #9488: MISRA addon: False positive for rule 10.6 in test for rule…
Browse files Browse the repository at this point in the history
… 10.1 (danmar#5598)
  • Loading branch information
swasti16 authored Oct 30, 2023
1 parent 915b4b6 commit 1284470
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2387,6 +2387,9 @@ def misra_10_6(self, data):
e = getEssentialType(token.astOperand2)
if not e:
continue
if e == "char" and vt1.type == "int":
# When arithmetic operations are performed on char values, they are usually promoted to int
continue
lhsbits = vt1.bits if vt1.bits else bitsOfEssentialType(vt1.type)
if lhsbits > bitsOfEssentialType(e):
self.reportError(token, 10, 6)
Expand Down
2 changes: 1 addition & 1 deletion addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ static void misra_10_6(u8 x, char c1, char c2) {
u16 y1 = x+x; // 10.6
u16 y2 = (0x100u - 0x80u); // rhs is not a composite expression because it's a constant expression
u16 z = ~u8 x ;//10.6
s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488
s32 i = c1 - c2; // 10.3
struct misra_10_6_s s;
s.a = x & 1U; // no-warning (#10487)
}
Expand Down

0 comments on commit 1284470

Please sign in to comment.