From 6d77a791ac3efe5a44d91da161275dc992116af5 Mon Sep 17 00:00:00 2001 From: Pavel Avgustinov Date: Thu, 4 Oct 2018 14:25:59 +0100 Subject: [PATCH] UseInOwnInitialiser: Refactor logic slightly. By pulling out the class `VariableAccessInInitialiser`, we can avoid some redundant work on pathological databases, improving performance. --- cpp/ql/src/Likely Bugs/UseInOwnInitializer.ql | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cpp/ql/src/Likely Bugs/UseInOwnInitializer.ql b/cpp/ql/src/Likely Bugs/UseInOwnInitializer.ql index 16f1f9af4a78..71d4c50f7e3d 100644 --- a/cpp/ql/src/Likely Bugs/UseInOwnInitializer.ql +++ b/cpp/ql/src/Likely Bugs/UseInOwnInitializer.ql @@ -11,10 +11,21 @@ import cpp -from Initializer init, Variable v, VariableAccess va -where init.getDeclaration() = v - and va.getTarget() = v - and va.getParent*() = init +class VariableAccessInInitializer extends VariableAccess { + Variable var; + Initializer init; + VariableAccessInInitializer() { + init.getDeclaration() = var and + init.getExpr().getAChild*() = this + } + + predicate initializesItself(Variable v, Initializer i) { + v = var and i = init and var = this.getTarget() + } +} + +from Initializer init, Variable v, VariableAccessInInitializer va +where va.initializesItself(v, init) and ( va.hasLValueToRValueConversion() or exists (Assignment assn | assn.getLValue() = va) or