mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
C++: Add testcase demonstrating false positive
This commit is contained in:
@@ -14,3 +14,11 @@
|
||||
| test.cpp:84:7:84:11 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:92:17:92:22 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:113:6:113:10 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:129:17:129:21 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:134:19:134:23 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:138:21:138:25 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:141:7:141:11 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:144:32:144:36 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:147:41:147:45 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:150:32:150:36 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
| test.cpp:153:46:153:50 | ... = ... | Use of '=' where '==' may have been intended. |
|
||||
|
||||
@@ -123,4 +123,33 @@ void f2() {
|
||||
|
||||
if(sz = "def") { // GOOD: a == comparison with a string literal is probably not the intent here
|
||||
}
|
||||
}
|
||||
|
||||
void f3(int x, int y) {
|
||||
if(x == 1 && (y = 2)) { // GOOD [FALSE POSITIVE]: the programmer seems to be okay with unparenthesized
|
||||
// comparison operands, so the parenthesis was used to mark this
|
||||
// as an assignment
|
||||
}
|
||||
|
||||
if((x == 1) && (y = 2)) { // BAD
|
||||
}
|
||||
|
||||
long z = x;
|
||||
if(((z == 42) || (y = 2)) && (x == 1)) { // BAD
|
||||
}
|
||||
|
||||
if((y = 2) && (x == z || x == 1)) { // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
if(((x == 42) || x == 1) && (y = 2)) { // BAD
|
||||
}
|
||||
|
||||
if(x == 10 || (x == 42 && x == 1) && (y = 2)) { // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
if(x == 10 || ((x == 42) && (y = 2)) && (z == 1)) { // BAD
|
||||
}
|
||||
|
||||
if((x == 10) || ((z == z) && (x == 1)) && (y = 2)) { // BAD
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user