Skip to content

Commit 6d18b4e

Browse files
committed
C++: If we don't have a valuetext, then see if one of our conversions does
1 parent 95794f9 commit 6d18b4e

File tree

1 file changed

+15
-5
lines changed
  • cpp/ql/src/semmle/code/cpp/exprs

1 file changed

+15
-5
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,23 @@ class Expr extends StmtParent, @expr {
8787
/** Gets the value of this expression, if it is a constant. */
8888
string getValue() { exists(@value v | values(v,result) and valuebind(v,underlyingElement(this))) }
8989

90+
private string getValueTextFollowingConversions(Expr e) {
91+
e.getValue() = this.getValue()
92+
and
93+
(if exists(@value v |
94+
valuebind(v,underlyingElement(e)) and
95+
valuetext(v, _))
96+
then exists(@value v |
97+
valuebind(v,underlyingElement(e)) and
98+
valuetext(v, result))
99+
else result = this.getValueTextFollowingConversions(e.getConversion()))
100+
}
101+
90102
/** Gets the source text for the value of this expression, if it is a constant. */
91103
string getValueText() {
92-
exists(@value v |
93-
valuebind(v,underlyingElement(this)) and
94-
if valuetext(v, _)
95-
then valuetext(v, result)
96-
else values(v, result))
104+
if exists(this.getValueTextFollowingConversions(this))
105+
then result = this.getValueTextFollowingConversions(this)
106+
else result = this.getValue()
97107
}
98108

99109
/** Holds if this expression has a value that can be determined at compile time. */

0 commit comments

Comments
 (0)