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

Method misra_20_7

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

Source from the content-addressed store, hash-verified

3725 self.reportError(directive, 20, 5)
3726
3727 def misra_20_7(self, data):
3728 def find_string_concat(exp, arg, directive_args):
3729 # Handle concatenation of string literals, e.g.:
3730 # #define MACRO(A, B) (A " " B)
3731 # Addon should not report errors for both macro arguments.
3732 arg_pos = exp.find(arg, 0)
3733 need_check = False
3734 skip_next = False
3735 state_in_string = False
3736 pos_search = arg_pos + 1
3737 directive_args = [a.strip() for a in directive_args if a != arg]
3738 arg = arg.strip()
3739 while pos_search < len(exp):
3740 if exp[pos_search] == '"':
3741 if state_in_string:
3742 state_in_string = False
3743 else:
3744 state_in_string = True
3745 pos_search += 1
3746 elif exp[pos_search].isalnum():
3747 word = ""
3748 while pos_search < len(exp) and exp[pos_search].isalnum():
3749 word += exp[pos_search]
3750 pos_search += 1
3751 if word == arg:
3752 pos_search += 1
3753 elif word in directive_args:
3754 skip_next = True
3755 break
3756 elif exp[pos_search] == ' ':
3757 pos_search += 1
3758 elif state_in_string:
3759 pos_search += 1
3760 else:
3761 need_check = True
3762 break
3763 return need_check, skip_next
3764
3765 for directive in data.directives:
3766 d = Define(directive)
3767 exp = '(' + d.expansionList + ')'
3768 skip_next = False
3769 for arg in d.args:
3770 if skip_next:
3771 _, skip_next = find_string_concat(exp, arg, d.args)
3772 continue
3773 need_check, skip_next = find_string_concat(exp, arg, d.args)
3774 if not need_check:
3775 continue
3776
3777 pos = 0
3778 while pos < len(exp):
3779 pos = exp.find(arg, pos)
3780 if pos < 0:
3781 break
3782 # is 'arg' used at position pos
3783 pos1 = pos - 1
3784 pos2 = pos + len(arg)

Callers

nothing calls this directly

Calls 4

reportErrorMethod · 0.95
isalnumFunction · 0.85
DefineClass · 0.70
findMethod · 0.45

Tested by

no test coverage detected