mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Apply code review suggestion to increase precision in getValue
This commit is contained in:
committed by
Ian Lynagh
parent
bc84ff2031
commit
5498f41248
@@ -25,12 +25,11 @@ class LiveLiteral extends MethodAccess {
|
||||
* This predicate gets the constant value held by the private field.
|
||||
*/
|
||||
CompileTimeConstantExpr getValue() {
|
||||
result =
|
||||
any(ReturnStmt r | this.getMethod().calls(r.getEnclosingCallable()))
|
||||
.getResult()
|
||||
.(VarAccess)
|
||||
.getVariable()
|
||||
.getInitializer()
|
||||
exists(MethodAccess getterCall, VarAccess va |
|
||||
methodReturns(this.getMethod(), getterCall) and
|
||||
methodReturns(getterCall.getMethod(), va) and
|
||||
result = va.getVariable().getInitializer()
|
||||
)
|
||||
}
|
||||
|
||||
override string toString() { result = this.getValue().toString() }
|
||||
@@ -40,3 +39,10 @@ class LiveLiteral extends MethodAccess {
|
||||
class LiveLiteralMethod extends Method {
|
||||
LiveLiteralMethod() { this.getDeclaringType().getName().matches("LiveLiterals$%") }
|
||||
}
|
||||
|
||||
private predicate methodReturns(Method m, Expr res) {
|
||||
exists(ReturnStmt r |
|
||||
r.getResult() = res and
|
||||
r.getEnclosingCallable() = m
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user