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

Method misra_21_14

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

Source from the content-addressed store, hash-verified

4020 self.reportError(token, 21, 12)
4021
4022 def misra_21_14(self, data):
4023 # buffers used in strcpy/strlen/etc function calls
4024 string_buffers = []
4025 for token in data.tokenlist:
4026 if token.str[0] == 's' and isFunctionCall(token.next, data.standards.c):
4027 name, args = cppcheckdata.get_function_call_name_args(token)
4028 if name is None:
4029 continue
4030 def _get_string_buffers(match, args, argnum):
4031 if not match:
4032 return []
4033 ret = []
4034 for a in argnum:
4035 if a < len(args):
4036 arg = args[a]
4037 while arg and arg.str in ('.', '::'):
4038 arg = arg.astOperand2
4039 if arg and arg.varId != 0 and arg.varId not in ret:
4040 ret.append(arg.varId)
4041 return ret
4042 string_buffers += _get_string_buffers(name == 'strcpy', args, [0, 1])
4043 string_buffers += _get_string_buffers(name == 'strncpy', args, [0, 1])
4044 string_buffers += _get_string_buffers(name == 'strlen', args, [0])
4045 string_buffers += _get_string_buffers(name == 'strcmp', args, [0, 1])
4046 string_buffers += _get_string_buffers(name == 'sprintf', args, [0])
4047 string_buffers += _get_string_buffers(name == 'snprintf', args, [0, 3])
4048
4049 for token in data.tokenlist:
4050 if token.str != 'memcmp':
4051 continue
4052 name, args = cppcheckdata.get_function_call_name_args(token)
4053 if name is None:
4054 continue
4055 if len(args) != 3:
4056 continue
4057 for arg in args[:2]:
4058 if arg.str[-1] == '\"':
4059 self.reportError(arg, 21, 14)
4060 continue
4061 while arg and arg.str in ('.', '::'):
4062 arg = arg.astOperand2
4063 if arg and arg.varId and arg.varId in string_buffers:
4064 self.reportError(arg, 21, 14)
4065
4066 def misra_21_15(self, data):
4067 for token in data.tokenlist:

Callers

nothing calls this directly

Calls 2

reportErrorMethod · 0.95
isFunctionCallFunction · 0.70

Tested by

no test coverage detected