Skip to content

Commit c120c59

Browse files
committed
Fixed #10446 (FP: misra-c2012-10.1 (u8 & 0x42U))
1 parent 6f4ce48 commit c120c59

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

addons/misra.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ def getEssentialTypeCategory(expr):
446446
if expr.variable:
447447
typeToken = expr.variable.typeStartToken
448448
while typeToken:
449+
if typeToken.str == 'char' and not typeToken.isSigned and not typeToken.isUnsigned:
450+
return 'char'
449451
if typeToken.valueType:
450452
if typeToken.valueType.type == 'bool':
451453
return typeToken.valueType.type
@@ -510,6 +512,8 @@ def getEssentialType(expr):
510512
if expr.valueType.isFloat():
511513
return expr.valueType.type
512514
if expr.valueType.isIntegral():
515+
if (expr.valueType.sign is None) and expr.valueType.type == 'char':
516+
return 'char'
513517
return '%s %s' % (expr.valueType.sign, expr.valueType.type)
514518

515519
elif expr.isNumber:
@@ -2082,11 +2086,9 @@ def misra_10_1(self, data):
20822086
elif not isUnsignedType(e2) and not token.astOperand2.isNumber:
20832087
self.reportError(token, 10, 1)
20842088
elif token.str in ('~', '&', '|', '^'):
2085-
def _is_char(essential_type):
2086-
return essential_type and (essential_type.split(' ')[-1] == 'char')
20872089
e1_et = getEssentialType(token.astOperand1)
20882090
e2_et = getEssentialType(token.astOperand2)
2089-
if _is_char(e1_et) and _is_char(e2_et):
2091+
if e1_et == 'char' or e2_et == 'char':
20902092
self.reportError(token, 10, 1)
20912093

20922094
def misra_10_2(self, data):

addons/test/misra/misra-test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ static void misra_9_5(void) {
600600

601601
typedef char misra_10_1_char_t;
602602
#define MISRA_10_1_CHAR char
603-
static void misra_10_1(uint32_t u, char c1, char c2) {
603+
static void misra_10_1(uint32_t u, char c1, char c2, uint8_t u8) {
604604
int32_t i;
605605
char c;
606606
enum { E1 = 1 };
@@ -625,6 +625,8 @@ static void misra_10_1(uint32_t u, char c1, char c2) {
625625
MISRA_10_1_CHAR cd2 = 'b';
626626
MISRA_10_1_CHAR cd3;
627627
cd3 = cd1 & cd2; // 10.1
628+
629+
uint8_t temp1 = u8 & 0x42U; // no-warning
628630
}
629631
static void misra_10_1_ternary(void)
630632
{
@@ -705,7 +707,7 @@ static void misra_10_6(u8 x, u32 a, u32 b, char c1, char c2) {
705707
u16 y = x+x; // 10.6
706708
u16 z = ~u8 x ;//10.6
707709
u32 c = ( u16) ( u32 a + u32 b ); //10.6
708-
s32 i = c1 - c2; // FIXME: False positive for 10.6 (this is compliant). Trac #9488
710+
s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488
709711
}
710712
static void misra_10_6_1(uint32_t *a, uint16_t b, uint16_t c)
711713
{

0 commit comments

Comments
 (0)