MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / misra_11_4

Method misra_11_4

addons/misra.py:2719–2755  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

2717 self.reportError(token, 11, 3)
2718
2719 def misra_11_4(self, data):
2720 # Get list of macro definitions
2721 macros = {}
2722 for directive in data.directives:
2723 #define X ((peripheral_t *)0x40000U)
2724 res = re.match(r'#define ([A-Za-z0-9_]+).*', directive.str)
2725 if res:
2726 if res.group(1) in macros:
2727 macros[res.group(1)].append(directive)
2728 else:
2729 macros[res.group(1)] = [directive]
2730
2731 # If macro definition is non-compliant then warn about the macro definition instead of
2732 # the macro usages. To reduce diagnostics for a non-compliant macro.
2733 bad_macros = []
2734 for token in data.tokenlist:
2735 if not isCast(token):
2736 continue
2737 vt1 = token.valueType
2738 vt2 = token.astOperand1.valueType
2739 if not vt1 or not vt2:
2740 continue
2741 if vt2.pointer > 0 and vt1.pointer == 0 and (vt1.isIntegral() or vt1.isEnum()) and vt2.type != 'void':
2742 self.reportError(token, 11, 4)
2743 elif vt1.pointer > 0 and vt2.pointer == 0 and (vt2.isIntegral() or vt2.isEnum()) and vt1.type != 'void':
2744 if token.macroName is not None and \
2745 token.macroName == token.astOperand1.macroName and \
2746 token.astOperand1.isInt and \
2747 token.link.previous.str == '*' and \
2748 token.macroName == token.link.previous.macroName and \
2749 token.macroName in macros and \
2750 len(macros[token.macroName]) == 1:
2751 if token.macroName not in bad_macros:
2752 bad_macros.append(token.macroName)
2753 self.reportError(macros[token.macroName][0], 11, 4)
2754 continue
2755 self.reportError(token, 11, 4)
2756
2757 def misra_11_5(self, data):
2758 for token in data.tokenlist:

Callers

nothing calls this directly

Calls 5

reportErrorMethod · 0.95
isIntegralMethod · 0.80
isEnumMethod · 0.80
isCastFunction · 0.70
matchMethod · 0.45

Tested by

no test coverage detected