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

Skip to content

Commit 428e357

Browse files
committed
C++: Add testcase demonstrating false positive
1 parent 7e84453 commit 428e357

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/AssignWhereCompareMeant/AssignWhereCompareMeant.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
| test.cpp:82:7:82:11 | ... = ... | Use of '=' where '==' may have been intended. |
1414
| test.cpp:84:7:84:11 | ... = ... | Use of '=' where '==' may have been intended. |
1515
| test.cpp:92:17:92:22 | ... = ... | Use of '=' where '==' may have been intended. |
16+
| test.cpp:105:6:105:10 | ... = ... | Use of '=' where '==' may have been intended. |
17+
| test.cpp:113:6:113:10 | ... = ... | Use of '=' where '==' may have been intended. |
18+
| test.cpp:113:6:113:10 | ... = ... | Use of '=' where '==' may have been intended. |

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/AssignWhereCompareMeant/test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,22 @@ void g(int *i_p, int cond) {
9898
if (y = 1) { // GOOD: y might not be initialized so it is probably intentional.
9999
}
100100
}
101+
102+
template<typename>
103+
void h() {
104+
int x;
105+
if(x = 0) { // GOOD [FALSE POSITIVE]: x is not initialized so this is probably intensional
106+
}
107+
108+
int y = 0;
109+
if((y = 1)) { // GOOD
110+
}
111+
112+
int z = 0;
113+
if(z = 1) { // BAD
114+
}
115+
}
116+
117+
void f() {
118+
h<int>();
119+
}

0 commit comments

Comments
 (0)