-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16497 from github/max-schaefer/comparison-with-wi…
…der-type Java: Add tests for `comparison-with-wider-type`.
- Loading branch information
Showing
4 changed files
with
39 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
java/ql/test/query-tests/security/CWE-190/semmle/tests/ComparisonWithWiderType.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| ComparisonWithWiderType.java:4:25:4:29 | ... < ... | Comparison between $@ of type int and $@ of wider type long. | ComparisonWithWiderType.java:4:25:4:25 | i | expression | ComparisonWithWiderType.java:4:29:4:29 | l | expression | | ||
| ComparisonWithWiderType.java:16:26:16:30 | ... > ... | Comparison between $@ of type byte and $@ of wider type short. | ComparisonWithWiderType.java:16:30:16:30 | b | expression | ComparisonWithWiderType.java:16:26:16:26 | c | expression | |
27 changes: 27 additions & 0 deletions
27
java/ql/test/query-tests/security/CWE-190/semmle/tests/ComparisonWithWiderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public class ComparisonWithWiderType { | ||
public void testLt(long l) { | ||
// BAD: loop variable is an int, but the upper bound is a long | ||
for (int i = 0; i < l; i++) { | ||
System.out.println(i); | ||
} | ||
|
||
// GOOD: loop variable is a long | ||
for (long i = 0; i < l; i++) { | ||
System.out.println(i); | ||
} | ||
} | ||
|
||
public void testGt(short c) { | ||
// BAD: loop variable is a byte, but the upper bound is a short | ||
for (byte b = 0; c > b; b++) { | ||
System.out.println(b); | ||
} | ||
} | ||
|
||
public void testLe(int i) { | ||
// GOOD: loop variable is a long, and the upper bound is an int | ||
for (long l = 0; l <= i; l++) { | ||
System.out.println(l); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
java/ql/test/query-tests/security/CWE-190/semmle/tests/ComparisonWithWiderType.qlref
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Security/CWE/CWE-190/ComparisonWithWiderType.ql |