misra; Robustness. Fix AttributeErrors. getEssentialType might return None.
This commit is contained in:
parent
ca047e57bf
commit
43fa7d2ebe
|
@ -527,11 +527,11 @@ def getEssentialType(expr):
|
||||||
return None
|
return None
|
||||||
e1 = getEssentialType(expr.astOperand1)
|
e1 = getEssentialType(expr.astOperand1)
|
||||||
e2 = getEssentialType(expr.astOperand2)
|
e2 = getEssentialType(expr.astOperand2)
|
||||||
if not e1 or not e2:
|
if e1 is None or e2 is None:
|
||||||
return None
|
return None
|
||||||
if is_constant_integer_expression(expr):
|
if is_constant_integer_expression(expr):
|
||||||
sign1 = e1.split(' ')[0]
|
sign1 = e1.split(' ')[0]
|
||||||
sign2 = e1.split(' ')[0]
|
sign2 = e2.split(' ')[0]
|
||||||
if sign1 == sign2 and sign1 in ('signed', 'unsigned'):
|
if sign1 == sign2 and sign1 in ('signed', 'unsigned'):
|
||||||
e = get_essential_type_from_value(expr.getKnownIntValue(), sign1 == 'signed')
|
e = get_essential_type_from_value(expr.getKnownIntValue(), sign1 == 'signed')
|
||||||
if e:
|
if e:
|
||||||
|
@ -2074,9 +2074,11 @@ class MisraChecker:
|
||||||
elif not isUnsignedType(e2) and not token.astOperand2.isNumber:
|
elif not isUnsignedType(e2) and not token.astOperand2.isNumber:
|
||||||
self.reportError(token, 10, 1)
|
self.reportError(token, 10, 1)
|
||||||
elif token.str in ('~', '&', '|', '^'):
|
elif token.str in ('~', '&', '|', '^'):
|
||||||
e1_et = getEssentialType(token.astOperand1).split(' ')[-1]
|
def _is_char(essential_type):
|
||||||
e2_et = getEssentialType(token.astOperand2).split(' ')[-1]
|
return essential_type and (essential_type.split(' ')[-1] == 'char')
|
||||||
if e1_et == 'char' and e2_et == 'char':
|
e1_et = getEssentialType(token.astOperand1)
|
||||||
|
e2_et = getEssentialType(token.astOperand2)
|
||||||
|
if _is_char(e1_et) and _is_char(e2_et):
|
||||||
self.reportError(token, 10, 1)
|
self.reportError(token, 10, 1)
|
||||||
|
|
||||||
def misra_10_2(self, data):
|
def misra_10_2(self, data):
|
||||||
|
|
Loading…
Reference in New Issue