From c1fcf78f16b6676c61290e8de2d557d6113f4080 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Thu, 16 Jan 2020 16:14:55 +0100 Subject: [PATCH] C++: Fold predicate sameLocation --- .../ImplicitFunctionDeclaration.ql | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cpp/ql/src/Likely Bugs/Underspecified Functions/ImplicitFunctionDeclaration.ql b/cpp/ql/src/Likely Bugs/Underspecified Functions/ImplicitFunctionDeclaration.ql index 9d80e95ec11..6caa4ad07f1 100644 --- a/cpp/ql/src/Likely Bugs/Underspecified Functions/ImplicitFunctionDeclaration.ql +++ b/cpp/ql/src/Likely Bugs/Underspecified Functions/ImplicitFunctionDeclaration.ql @@ -17,10 +17,17 @@ import TooFewArguments import TooManyArguments import semmle.code.cpp.commons.Exclusions -predicate sameLocation(Location loc1, Location loc2) { - loc1.getFile() = loc2.getFile() and - loc1.getStartLine() = loc2.getStartLine() and - loc1.getStartColumn() = loc2.getStartColumn() +predicate locInfo(Locatable e, File file, int line, int col) { + e.getFile() = file and + e.getLocation().getStartLine() = line and + e.getLocation().getStartColumn() = col +} + +predicate sameLocation(FunctionDeclarationEntry fde, FunctionCall fc) { + exists(File file, int line, int col | + locInfo(fde, file, line, col) and + locInfo(fc, file, line, col) + ) } predicate isCompiledAsC(File f) { @@ -34,7 +41,7 @@ where isCompiledAsC(fdeIm.getFile()) and not isFromMacroDefinition(fc) and fdeIm.isImplicit() and - sameLocation(fdeIm.getLocation(), fc.getLocation()) and + sameLocation(fdeIm, fc) and not mistypedFunctionArguments(fc, _, _) and not tooFewArguments(fc, _) and not tooManyArguments(fc, _)