Fixed #10446 (FP: misra-c2012-10.1 (u8 & 0x42U))
This commit is contained in:
parent
6f4ce486a2
commit
c120c59912
|
@ -446,6 +446,8 @@ def getEssentialTypeCategory(expr):
|
|||
if expr.variable:
|
||||
typeToken = expr.variable.typeStartToken
|
||||
while typeToken:
|
||||
if typeToken.str == 'char' and not typeToken.isSigned and not typeToken.isUnsigned:
|
||||
return 'char'
|
||||
if typeToken.valueType:
|
||||
if typeToken.valueType.type == 'bool':
|
||||
return typeToken.valueType.type
|
||||
|
@ -510,6 +512,8 @@ def getEssentialType(expr):
|
|||
if expr.valueType.isFloat():
|
||||
return expr.valueType.type
|
||||
if expr.valueType.isIntegral():
|
||||
if (expr.valueType.sign is None) and expr.valueType.type == 'char':
|
||||
return 'char'
|
||||
return '%s %s' % (expr.valueType.sign, expr.valueType.type)
|
||||
|
||||
elif expr.isNumber:
|
||||
|
@ -2082,11 +2086,9 @@ class MisraChecker:
|
|||
elif not isUnsignedType(e2) and not token.astOperand2.isNumber:
|
||||
self.reportError(token, 10, 1)
|
||||
elif token.str in ('~', '&', '|', '^'):
|
||||
def _is_char(essential_type):
|
||||
return essential_type and (essential_type.split(' ')[-1] == 'char')
|
||||
e1_et = getEssentialType(token.astOperand1)
|
||||
e2_et = getEssentialType(token.astOperand2)
|
||||
if _is_char(e1_et) and _is_char(e2_et):
|
||||
if e1_et == 'char' or e2_et == 'char':
|
||||
self.reportError(token, 10, 1)
|
||||
|
||||
def misra_10_2(self, data):
|
||||
|
|
|
@ -600,7 +600,7 @@ static void misra_9_5(void) {
|
|||
|
||||
typedef char misra_10_1_char_t;
|
||||
#define MISRA_10_1_CHAR char
|
||||
static void misra_10_1(uint32_t u, char c1, char c2) {
|
||||
static void misra_10_1(uint32_t u, char c1, char c2, uint8_t u8) {
|
||||
int32_t i;
|
||||
char c;
|
||||
enum { E1 = 1 };
|
||||
|
@ -625,6 +625,8 @@ static void misra_10_1(uint32_t u, char c1, char c2) {
|
|||
MISRA_10_1_CHAR cd2 = 'b';
|
||||
MISRA_10_1_CHAR cd3;
|
||||
cd3 = cd1 & cd2; // 10.1
|
||||
|
||||
uint8_t temp1 = u8 & 0x42U; // no-warning
|
||||
}
|
||||
static void misra_10_1_ternary(void)
|
||||
{
|
||||
|
@ -705,7 +707,7 @@ static void misra_10_6(u8 x, u32 a, u32 b, char c1, char c2) {
|
|||
u16 y = x+x; // 10.6
|
||||
u16 z = ~u8 x ;//10.6
|
||||
u32 c = ( u16) ( u32 a + u32 b ); //10.6
|
||||
s32 i = c1 - c2; // FIXME: False positive for 10.6 (this is compliant). Trac #9488
|
||||
s32 i = c1 - c2; // 10.3 FIXME: False positive for 10.6 (this is compliant). Trac #9488
|
||||
}
|
||||
static void misra_10_6_1(uint32_t *a, uint16_t b, uint16_t c)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue