diff --git a/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql b/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql index b68203c2a91..8ff5d438c43 100644 --- a/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql +++ b/cpp/ql/src/Likely Bugs/Arithmetic/PointlessComparison.ql @@ -31,7 +31,7 @@ from where not cmp.isInMacroExpansion() and not cmp.isFromTemplateInstantiation(_) and - not containsDisabledCode(cmp.getEnclosingFunction()) and + not functionContainsDisabledCode(cmp.getEnclosingFunction()) and reachablePointlessComparison(cmp, left, right, value, ss) and // a comparison between an enum and zero is always valid because whether diff --git a/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql b/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql index e19767b9f76..12b95096be8 100644 --- a/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql +++ b/cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql @@ -27,12 +27,12 @@ predicate accessInInitOfForStmt(Expr e) { * Holds if the function `f`, or a function called by it, contains * code excluded by the preprocessor. */ -predicate containsDisabledCodeRecursive(Function f) { - containsDisabledCode(f) or +predicate functionContainsDisabledCodeRecursive(Function f) { + functionContainsDisabledCode(f) or // recurse into function calls exists(FunctionCall fc | fc.getEnclosingFunction() = f and - containsDisabledCode(fc.getTarget()) + functionContainsDisabledCodeRecursive(fc.getTarget()) ) } @@ -40,12 +40,12 @@ predicate containsDisabledCodeRecursive(Function f) { * Holds if the function `f`, or a function called by it, is inside a * preprocessor branch that may have code in another arm */ -predicate definedInIfDefRecursive(Function f) { - definedInIfDef(f) or +predicate functionDefinedInIfDefRecursive(Function f) { + functionDefinedInIfDef(f) or // recurse into function calls exists(FunctionCall fc | fc.getEnclosingFunction() = f and - definedInIfDef(fc.getTarget()) + functionDefinedInIfDefRecursive(fc.getTarget()) ) } @@ -79,8 +79,8 @@ where // EQExprs are covered by CompareWhereAssignMeant.ql not parent instanceof PureExprInVoidContext and not peivc.getEnclosingFunction().isCompilerGenerated() and not peivc.getType() instanceof UnknownType and - not containsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and - not definedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and + not functionContainsDisabledCodeRecursive(peivc.(FunctionCall).getTarget()) and + not functionDefinedInIfDefRecursive(peivc.(FunctionCall).getTarget()) and if peivc instanceof FunctionCall then exists(Function target | target = peivc.(FunctionCall).getTarget() and diff --git a/cpp/ql/src/semmle/code/cpp/Preprocessor.qll b/cpp/ql/src/semmle/code/cpp/Preprocessor.qll index fe8cbe0701d..1d188138623 100644 --- a/cpp/ql/src/semmle/code/cpp/Preprocessor.qll +++ b/cpp/ql/src/semmle/code/cpp/Preprocessor.qll @@ -239,7 +239,7 @@ private predicate functionLocation(Function f, string file, int fBlockStartLine, /** * Holds if the function `f` is inside a preprocessor branch that may have code in another arm. */ -predicate definedInIfDef(Function f) { +predicate functionDefinedInIfDef(Function f) { exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int pbdEndLine, int fBlockStartLine, int fBlockEndLine | functionLocation(f, file, fBlockStartLine, fBlockEndLine) and @@ -258,13 +258,12 @@ predicate definedInIfDef(Function f) { } /** - * Holds if the function `f`, or a function called by it, contains - * code excluded by the preprocessor. + * Holds if the function `f` contains code excluded by the preprocessor. */ -predicate containsDisabledCode(Function f) { +predicate functionContainsDisabledCode(Function f) { // `f` contains a preprocessor branch that was not taken exists(PreprocessorBranchDirective pbd, string file, int pbdStartLine, int fBlockStartLine, int fBlockEndLine | - functionLocation(f, file, fBlockStartLine, fBlockEndLine) and + functionLocation(f, file, fBlockStartLine, fBlockEndLine) and pbdLocation(pbd, file, pbdStartLine) and pbdStartLine <= fBlockEndLine and pbdStartLine >= fBlockStartLine and @@ -275,10 +274,5 @@ predicate containsDisabledCode(Function f) { // was not taken. pbd instanceof PreprocessorElse ) - ) or - // recurse into function calls - exists(FunctionCall fc | - fc.getEnclosingFunction() = f and - containsDisabledCode(fc.getTarget()) ) }