Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21ff1a0

Browse files
committed
Address some of the PR review findings
1 parent 638d039 commit 21ff1a0

5 files changed

Lines changed: 37 additions & 30 deletions

File tree

csharp/ql/src/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisCommon.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ private Sign certainExprSign(Expr e) {
4141
)
4242
}
4343

44+
/**
45+
* Gets the value of the expression if it can't be converted to integer, but
46+
* can be converted to float.
47+
*/
48+
float getNonIntegerValue(ExprWithPossibleValue e) {
49+
exists(string s |
50+
s = e.getValue() and
51+
result = s.toFloat() and
52+
not exists(s.toInt())
53+
)
54+
}
55+
4456
/** Holds if the sign of `e` is too complicated to determine. */
4557
predicate unknownSign(Expr e) {
4658
not exists(certainExprSign(e)) and
@@ -55,7 +67,7 @@ predicate unknownSign(Expr e) {
5567
not fromtyp instanceof NumericOrCharType
5668
)
5769
or
58-
unknownIntegerAccess(e)
70+
numericExprWithUnknownSign(e)
5971
)
6072
}
6173

@@ -246,7 +258,7 @@ private Sign ssaDefSign(SsaVariable v) {
246258
}
247259

248260
/** Returns the sign of explicit SSA definition `v`. */
249-
Sign explicitSsaDefSign(SsaVariable v) {
261+
private Sign explicitSsaDefSign(SsaVariable v) {
250262
exists(VariableUpdate def | def = getExplicitSsaAssignment(v) |
251263
result = exprSign(getExprFromSsaAssignment(def))
252264
or

csharp/ql/src/semmle/code/csharp/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ module Private {
3434

3535
class VariableUpdate = CS::AssignableDefinition;
3636

37+
class ExprWithPossibleValue = CS::Expr;
38+
3739
predicate ssaRead = SU::ssaRead/2;
3840
}
3941

@@ -50,18 +52,6 @@ private module Impl {
5052

5153
private class BooleanValue = AbstractValues::BooleanValue;
5254

53-
/**
54-
* Gets the value of the expression if it can't be converted to integer, but
55-
* can be converted to float.
56-
*/
57-
float getNonIntegerValue(Expr e) {
58-
exists(string s |
59-
s = e.getValue() and
60-
result = s.toFloat() and
61-
not exists(s.toInt())
62-
)
63-
}
64-
6555
/** Gets the character value of expression `e`. */
6656
string getCharValue(Expr e) { result = e.getValue() and e.getType() instanceof CharType }
6757

@@ -162,7 +152,7 @@ private module Impl {
162152
/**
163153
* Holds if `e` has type `NumericOrCharType`, but the sign of `e` is unknown.
164154
*/
165-
predicate unknownIntegerAccess(Expr e) {
155+
predicate numericExprWithUnknownSign(Expr e) {
166156
e.getType() instanceof NumericOrCharType and
167157
not e = getARead(_) and
168158
not e instanceof FieldAccess and

java/ql/src/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisCommon.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ private Sign certainExprSign(Expr e) {
4141
)
4242
}
4343

44+
/**
45+
* Gets the value of the expression if it can't be converted to integer, but
46+
* can be converted to float.
47+
*/
48+
float getNonIntegerValue(ExprWithPossibleValue e) {
49+
exists(string s |
50+
s = e.getValue() and
51+
result = s.toFloat() and
52+
not exists(s.toInt())
53+
)
54+
}
55+
4456
/** Holds if the sign of `e` is too complicated to determine. */
4557
predicate unknownSign(Expr e) {
4658
not exists(certainExprSign(e)) and
@@ -55,7 +67,7 @@ predicate unknownSign(Expr e) {
5567
not fromtyp instanceof NumericOrCharType
5668
)
5769
or
58-
unknownIntegerAccess(e)
70+
numericExprWithUnknownSign(e)
5971
)
6072
}
6173

@@ -246,7 +258,7 @@ private Sign ssaDefSign(SsaVariable v) {
246258
}
247259

248260
/** Returns the sign of explicit SSA definition `v`. */
249-
Sign explicitSsaDefSign(SsaVariable v) {
261+
private Sign explicitSsaDefSign(SsaVariable v) {
250262
exists(VariableUpdate def | def = getExplicitSsaAssignment(v) |
251263
result = exprSign(getExprFromSsaAssignment(def))
252264
or

java/ql/src/semmle/code/java/dataflow/internal/rangeanalysis/SignAnalysisSpecific.qll

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Private {
3838

3939
class VariableUpdate = J::VariableUpdate;
4040

41+
class ExprWithPossibleValue = J::Literal;
42+
4143
predicate ssaRead = RU::ssaRead/2;
4244

4345
predicate guardControlsSsaRead = RU::guardControlsSsaRead/3;
@@ -57,15 +59,6 @@ private module Impl {
5759

5860
class UnsignedNumericType = CharacterType;
5961

60-
/**
61-
* Gets the `float` value of expression `e` where `e` has no `int` value.
62-
*/
63-
float getNonIntegerValue(Expr e) {
64-
result = e.(LongLiteral).getValue().toFloat() or
65-
result = e.(FloatingPointLiteral).getValue().toFloat() or
66-
result = e.(DoubleLiteral).getValue().toFloat()
67-
}
68-
6962
/** Gets the character value of expression `e`. */
7063
string getCharValue(Expr e) { result = e.(CharacterLiteral).getValue() }
7164

@@ -86,11 +79,10 @@ private module Impl {
8679

8780
/**
8881
* Holds if `e` has type `NumericOrCharType`, but the sign of `e` is unknown.
89-
*
90-
* The expression types handled in the predicate complements the expression
91-
* types handled in `specificSubExprSign`.
9282
*/
93-
predicate unknownIntegerAccess(Expr e) {
83+
predicate numericExprWithUnknownSign(Expr e) {
84+
// The expression types handled in the predicate complements the expression
85+
// types handled in `specificSubExprSign`.
9486
e instanceof ArrayAccess and e.getType() instanceof NumericOrCharType
9587
or
9688
e instanceof MethodAccess and e.getType() instanceof NumericOrCharType

java/ql/test/library-tests/dataflow/sign-analysis/SignAnalysis.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ string getASignString(Expr e) {
1818
}
1919

2020
from Expr e
21+
where not e instanceof Element or e.(Element).fromSource()
2122
select e, strictconcat(string s | s = getASignString(e) | s, " ")

0 commit comments

Comments
 (0)