Skip to content

Commit 5498f41

Browse files
atorralbaigfoo
authored andcommitted
Apply code review suggestion to increase precision in getValue
1 parent bc84ff2 commit 5498f41

File tree

1 file changed

+12
-6
lines changed
  • java/ql/lib/semmle/code/java/frameworks/android

1 file changed

+12
-6
lines changed

java/ql/lib/semmle/code/java/frameworks/android/Compose.qll

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ class LiveLiteral extends MethodAccess {
2525
* This predicate gets the constant value held by the private field.
2626
*/
2727
CompileTimeConstantExpr getValue() {
28-
result =
29-
any(ReturnStmt r | this.getMethod().calls(r.getEnclosingCallable()))
30-
.getResult()
31-
.(VarAccess)
32-
.getVariable()
33-
.getInitializer()
28+
exists(MethodAccess getterCall, VarAccess va |
29+
methodReturns(this.getMethod(), getterCall) and
30+
methodReturns(getterCall.getMethod(), va) and
31+
result = va.getVariable().getInitializer()
32+
)
3433
}
3534

3635
override string toString() { result = this.getValue().toString() }
@@ -40,3 +39,10 @@ class LiveLiteral extends MethodAccess {
4039
class LiveLiteralMethod extends Method {
4140
LiveLiteralMethod() { this.getDeclaringType().getName().matches("LiveLiterals$%") }
4241
}
42+
43+
private predicate methodReturns(Method m, Expr res) {
44+
exists(ReturnStmt r |
45+
r.getResult() = res and
46+
r.getEnclosingCallable() = m
47+
)
48+
}

0 commit comments

Comments
 (0)