def reportError(token, severity, msg, id): if id == 'debug' and DEBUG == False: return if VERIFY: VERIFY_ACTUAL.append(str(token.linenr) + ':' + id) else: cppcheckdata.reportError(token, severity, msg, 'misc', id)
def reportDiagnostic(template, configuration, file, line, severity, message): # collect diagnostics by configuration if not configuration in diagnostics: diagnostics[configuration] = [] # add error to this configuration diagnostics[configuration].append( cppcheckdata.reportError(template, [[file, line]], severity, message))
def reportDiagnostic(template, configuration, file, line, severity, message): # collect diagnostics by configuration if configuration not in diagnostics: diagnostics[configuration] = [] # add error to this configuration diagnostics[configuration].append( cppcheckdata.reportError(template, [[file, line]], severity, message))
def reportError(self, token, severity, msg, id): if token is None: if self.args.cli: message = { 'file': 'All files', 'linenr': 0, 'column': 0, 'severity': severity, 'message': msg, 'addon': 'HIS', 'errorId': id, 'extra': '' } sys.stdout.write(json.dumps(message) + '\n') else: sys.stderr.write('[' + 'All files' + ':' + '---' + '] (' + severity + ') ' + msg + ' [HIS-' + id + ']\n') else: if self.args.verify: self.verify_actual.append(token.file + ':' + str(token.linenr) + ':HIS-' + id) else: try: cppcheckdata.reportError(token, severity, msg, 'HIS', id) except ValueError: if self.args.cli: message = { 'file': token.file, 'linenr': token.linenr, 'column': token.column, 'severity': severity, 'message': msg, 'addon': 'HIS', 'errorId': id, 'extra': '' } sys.stdout.write(json.dumps(message) + '\n') else: sys.stderr.write('[' + token.file + ':' + str(token.linenr) + '] (' + severity + ') ' + msg + ' [HIS-' + id + ']\n') self.his_stats[id] = self.his_stats[id] + 1
def reportError(token, msg, id): cppcheckdata.reportError(token, 'warning', msg, 'mnn-rules', id)
def reportError(token, severity, msg, id): if VERIFY: VERIFY_ACTUAL.append(str(token.linenr) + ':cert-' + id) else: cppcheckdata.reportError(token, severity, msg, 'cert', id)
def reportError(token, severity, msg, errorId): cppcheckdata.reportError(token, severity, msg, 'naming', errorId)
data = cppcheckdata.CppcheckData(arg) for cfg in data.iterconfigurations(): print('Checking %s, config %s...' % (arg, cfg.name)) for token in cfg.tokenlist: if token.str != '(' or not token.astOperand1 or token.astOperand2: continue # Is it a lambda? if token.astOperand1.str == '{': continue # we probably have a cast.. if there is something inside the parentheses # there is a cast. Otherwise this is a function call. typetok = token.next if not typetok.isName: continue # cast number => skip output if token.astOperand1.isNumber: continue # void cast => often used to suppress compiler warnings if typetok.str == 'void': continue cppcheckdata.reportError(token, 'information', 'found a cast', 'findcasts', 'cast') sys.exit(cppcheckdata.EXIT_CODE)
def reportError(location, severity, message, errorId=None): cppcheckdata.reportError(location, severity, message, __addon_name__, errorId or __errorid__)
def check_y2038_safe(dumpfile, quiet=False): # at the start of the check, we don't know if code is Y2038 safe y2038safe = False # load XML from .dump file data = cppcheckdata.parsedump(dumpfile) # Convert dump file path to source file in format generated by cppcheck. # For example after the following call: # cppcheck ./src/my-src.c --dump # We got 'src/my-src.c' value for 'file' field in cppcheckdata. srcfile = dumpfile.rstrip('.dump') srcfile = os.path.expanduser(srcfile) srcfile = os.path.normpath(srcfile) # go through each configuration for cfg in data.configurations: cfg = data.Configuration(cfg) if not quiet: print('Checking ' + srcfile + ', config "' + cfg.name + '"...') safe_ranges = [] safe = -1 time_bits_defined = False srclinenr = '0' for directive in cfg.directives: # track source line number if directive.file == srcfile: srclinenr = directive.linenr # check for correct _TIME_BITS if present if re_define_time_bits_64.match(directive.str): time_bits_defined = True elif re_define_time_bits.match(directive.str): cppcheckdata.reportError( directive, 'error', '_TIME_BITS must be defined equal to 64', 'y2038', 'type-bits-not-64') time_bits_defined = False y2038safe = False elif re_undef_time_bits.match(directive.str): time_bits_defined = False # check for _USE_TIME_BITS64 (un)definition if re_define_use_time_bits64.match(directive.str): safe = int(srclinenr) # warn about _TIME_BITS not being defined if not time_bits_defined: cppcheckdata.reportError( directive, 'warning', '_USE_TIME_BITS64 is defined but _TIME_BITS was not', 'y2038', 'type-bits-undef') elif re_undef_use_time_bits64.match(directive.str): unsafe = int(srclinenr) # do we have a safe..unsafe area? if unsafe > safe > 0: safe_ranges.append((safe, unsafe)) safe = -1 # check end of source beyond last directive if len(cfg.tokenlist) > 0: unsafe = int(cfg.tokenlist[-1].linenr) if unsafe > safe > 0: safe_ranges.append((safe, unsafe)) # go through all tokens for token in cfg.tokenlist: if token.str in id_Y2038: if not any(lower <= int(token.linenr) <= upper for (lower, upper) in safe_ranges): cppcheckdata.reportError(token, 'warning', token.str + ' is Y2038-unsafe', 'y2038', 'unsafe-call') y2038safe = False token = token.next return y2038safe
def reportError(token, severity, msg, id): cppcheckdata.reportError(token, severity, msg, 'threadsafety', id)
print('Checking ' + arg + '...') data = cppcheckdata.parsedump(arg) for cfg in data.configurations: if len(data.configurations) > 1: print('Checking ' + arg + ', config "' + cfg.name + '"...') for token in cfg.tokenlist: if token.str != '(' or not token.astOperand1 or token.astOperand2: continue # Is it a lambda? if token.astOperand1.str == '{': continue # we probably have a cast.. if there is something inside the parentheses # there is a cast. Otherwise this is a function call. typetok = token.next if not typetok.isName: continue # cast number => skip output if token.astOperand1.isNumber: continue # void cast => often used to suppress compiler warnings if typetok.str == 'void': continue cppcheckdata.reportError(token, 'information', 'found a cast', 'findcasts', 'cast')