diff --git a/addons/cert.py b/addons/cert.py index 8f1abf2d4..fc397b133 100644 --- a/addons/cert.py +++ b/addons/cert.py @@ -26,7 +26,7 @@ def isUnpackedStruct(var): if structScope: linenr = int(structScope.classStart.linenr) for line in open(structScope.classStart.file): - linenr = linenr - 1 + linenr -= 1 if linenr == 0: return True if re.match(r'#pragma\s+pack\s*\(', line): diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py index 673a04a44..aea45b8bc 100644 --- a/addons/cppcheckdata.py +++ b/addons/cppcheckdata.py @@ -642,7 +642,7 @@ def astIsFloat(token): return False if token.str == '.': return astIsFloat(token.astOperand2) - if '+-*/%'.find(token.str) == 0: + if token.str in '+-*/%': return astIsFloat(token.astOperand1) or astIsFloat(token.astOperand2) if not token.variable: # float literal? diff --git a/addons/misra.py b/addons/misra.py index 5093a857d..563808ced 100644 --- a/addons/misra.py +++ b/addons/misra.py @@ -223,7 +223,7 @@ def isUnsignedInt(expr): if not expr: return False if expr.isNumber: - return expr.str.find('u') > 0 or expr.str.find('U') > 0 + return 'u' in expr.str or 'U' in expr.str if expr.str in {'+', '-', '*', '/', '%'}: return isUnsignedInt(expr.astOperand1) or isUnsignedInt(expr.astOperand2) return False @@ -811,7 +811,7 @@ def misra_16_3(rawTokens): else: state = 0 elif token.str.startswith('/*') or token.str.startswith('//'): - if token.str.lower().find('fallthrough') > 0: + if 'fallthrough' in token.str.lower(): state = 2 elif token.str == '{': state = 2 @@ -956,7 +956,7 @@ def misra_20_2(data): if not directive.str.startswith('#include '): continue for pattern in {'\\', '//', '/*', "'"}: - if directive.str.find(pattern) > 0: + if pattern in directive.str: reportError(directive, 20, 2) break diff --git a/test/synthetic/report.py b/test/synthetic/report.py index adc74c54d..e4d972102 100755 --- a/test/synthetic/report.py +++ b/test/synthetic/report.py @@ -23,10 +23,8 @@ def parsefile(filename): functionName = res.group(1) if line.startswith('}'): functionName = '' - elif line.find('BUG') > 0 or line.find('WARN') > 0 or filename == 'ub.c': - spaces = '' - for i in range(100): - spaces = spaces + ' ' + elif 'BUG' in line or 'WARN' in line or filename == 'ub.c': + spaces = ' ' * 100 s = filename + spaces s = s[:15] + str(linenr) + spaces s = s[:20] + functionName + spaces diff --git a/tools/daca2-addons.py b/tools/daca2-addons.py index f66e0448e..0f86571ae 100644 --- a/tools/daca2-addons.py +++ b/tools/daca2-addons.py @@ -53,7 +53,7 @@ def getpackages(folder): filename = None elif line[:13 + len(folder)] == './pool/main/' + folder + '/': path = line[2:-1] - elif path and line.find('.orig.tar.') > 0: + elif path and '.orig.tar.' in line: filename = line[1 + line.rfind(' '):] for a in archives: @@ -75,7 +75,7 @@ def handleRemoveReadonly(func, path, exc): def removeAllExceptResults(): count = 5 while count > 0: - count = count - 1 + count -= 1 filenames = [] for g in glob.glob('[A-Za-z0-9]*'): @@ -116,7 +116,7 @@ def removeLargeFiles(path): removeLargeFiles(g + '/') elif os.path.isfile(g) and g[-4:] != '.txt': statinfo = os.stat(g) - if path.find('/clang/INPUTS/') > 0 or statinfo.st_size > 100000: + if '/clang/INPUTS/' in path or statinfo.st_size > 100000: os.remove(g) @@ -194,7 +194,7 @@ def scanarchive(filepath, jobs): addons = sorted(glob.glob(os.path.expanduser('~/cppcheck/addons/*.py'))) for dumpfile in sorted(dumpfiles('')): for addon in addons: - if addon.find('cppcheckdata.py') > 0: + if 'cppcheckdata.py' in addon: continue p2 = subprocess.Popen(['nice', diff --git a/tools/daca2-download.py b/tools/daca2-download.py index 80d435d61..1b1e68c29 100644 --- a/tools/daca2-download.py +++ b/tools/daca2-download.py @@ -52,7 +52,7 @@ def getpackages(): filename = None elif line[:12] == './pool/main/': path = line[2:-1] - elif path and line.find('.orig.tar.') > 0: + elif path and '.orig.tar.' in line: filename = line[1 + line.rfind(' '):] for a in archives: @@ -74,7 +74,7 @@ def handleRemoveReadonly(func, path, exc): def removeAll(): count = 5 while count > 0: - count = count - 1 + count -= 1 filenames = [] for g in glob.glob('[#_A-Za-z0-9]*'): diff --git a/tools/daca2-report.py b/tools/daca2-report.py index 51337204d..fec676d1b 100644 --- a/tools/daca2-report.py +++ b/tools/daca2-report.py @@ -10,26 +10,26 @@ def readdate(data): else: datepos = data.find('\nDATE ') if datepos >= 0: - datepos = datepos + 1 + datepos += 1 if datepos < 0: return None datestr = '' - datepos = datepos + 5 + datepos += 5 while True: if datepos >= len(data): return None d = data[datepos] if d >= '0' and d <= '9': - datestr = datestr + d + datestr += d elif d == '\n' or d == '\r': if len(datestr) == 8: return datestr[:4] + '-' + datestr[4:6] + '-' + datestr[6:] return None elif d != ' ' and d != '-': return None - datepos = datepos + 1 + datepos += 1 daca2folder = os.path.expanduser('~/daca2/') path = '' @@ -37,11 +37,11 @@ for arg in sys.argv[1:]: if arg.startswith('--daca2='): daca2folder = arg[8:] if daca2folder[-1] != '/': - daca2folder = daca2folder + '/' + daca2folder += '/' else: path = arg if path[-1] != '/': - path = path + '/' + path += '/' mainpage = open(path + 'daca2.html', 'wt') mainpage.write('\n') diff --git a/tools/daca2.py b/tools/daca2.py index 0a4cea24e..506b74da2 100644 --- a/tools/daca2.py +++ b/tools/daca2.py @@ -55,7 +55,7 @@ def getpackages(folder): filename = None elif line[:13 + len(folder)] == './pool/main/' + folder + '/': path = line[2:-1] - elif path and line.find('.orig.tar.') > 0: + elif path and '.orig.tar.' in line: filename = line[1 + line.rfind(' '):] for a in archives: @@ -82,7 +82,7 @@ def removeAllExceptResults(): for filename in filenames: count = 5 while count > 0: - count = count - 1 + count -= 1 try: if os.path.isdir(filename): diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py index 92ec203a2..32e7fb46c 100755 --- a/tools/matchcompiler.py +++ b/tools/matchcompiler.py @@ -148,7 +148,7 @@ class MatchCompiler: gotoNextToken = ' tok = tok->next();\n' # if varid is provided, check that it's non-zero on first use - if varid and tok.find('%varid%') != -1 and checked_varid is False: + if varid and '%varid%' in tok and not checked_varid: ret += ' if (varid==0U)\n' ret += ' throw InternalError(tok, "Internal error. Token::Match called with varid 0. ' +\ 'Please report this to Cppcheck developers");\n' @@ -160,7 +160,7 @@ class MatchCompiler: ret += ' ' + returnStatement # a|b|c - elif tok.find('|') > 0: + elif '|' in tok: tokens2 = tok.split('|') logicalOp = ' || ' if "" in tokens2: @@ -537,7 +537,7 @@ class MatchCompiler: # Check for varId varId = None - if not is_findsimplematch and g0.find("%varid%") != -1: + if not is_findsimplematch and "%varid%" in g0: if len(res) == 5: varId = res[4] else: diff --git a/tools/parse-glibc.py b/tools/parse-glibc.py index fdefbc8c3..cb79edec8 100644 --- a/tools/parse-glibc.py +++ b/tools/parse-glibc.py @@ -19,9 +19,9 @@ def checknonnull(cfg, functionName, nonnull): continue argpos2 = functionCfg.find('', argpos1) notnullpos = functionCfg.find('not-null', argpos1) - if notnullpos > 0 and notnullpos < argpos2: + if 0 <= notnullpos < argpos2: if s: - s = s + ', ' + str(argnr) + s += ', ' + str(argnr) else: s = str(argnr) if s != nonnull: @@ -102,7 +102,7 @@ def parseheader(cppcheckpath, filename): nonnull = None nonnullStart = line.find('__nonnull') - if nonnullStart > 0: + if nonnullStart >= 0: nonnullStart += 9 while nonnullStart < len(line) and line[nonnullStart] == ' ': nonnullStart += 1 diff --git a/tools/reduce.py b/tools/reduce.py index 32da0d1f9..b81b3a82a 100644 --- a/tools/reduce.py +++ b/tools/reduce.py @@ -46,7 +46,7 @@ def runtool(): return True elif p.returncode == 0: out = comm[0] + '\n' + comm[1] - if ('error:' not in out) and (out.find(EXPECTED) > 0): + if 'error:' not in out and EXPECTED in out: return True return False @@ -223,7 +223,7 @@ def removeline(filedata): if stmt and strippedline[-1] == ';' and checkpar(line) and '{' not in line and '}' not in line: replaceandrun('remove line', filedata, i, '') - elif stmt and strippedline.find('{') > 0 and strippedline.find('}') == len(strippedline) - 1: + elif stmt and '{' in strippedline and strippedline.find('}') == len(strippedline) - 1: replaceandrun('remove line', filedata, i, '') if strippedline[-1] in ';{}': diff --git a/triage/triage-report.py b/triage/triage-report.py index 7a9dbebf7..cb7721221 100644 --- a/triage/triage-report.py +++ b/triage/triage-report.py @@ -71,7 +71,7 @@ for result in results.split('\n'): f = open(project + '/true-positives.txt', 'rt') for line in f.readlines(): line = line.strip() - if line.find('] -> [') > 0 or '(error)' not in line: + if '] -> [' in line or '(error)' not in line: continue res = re.match('\\[(' + project + '.+):([0-9]+)\\]:\s+[(][a-z]+[)] (.+)', line) @@ -101,7 +101,7 @@ for line in f.readlines(): f.close() project2 = '' -if project.find('-') > 0: +if '-' in project: project2 = project[:project.find('-')] else: project2 = project