File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
cpp/ql/test/query-tests/Likely Bugs/Likely Typos/AssignWhereCompareMeant Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1919| test.cpp:144:32:144:36 | ... = ... | Use of '=' where '==' may have been intended. |
2020| test.cpp:150:32:150:36 | ... = ... | Use of '=' where '==' may have been intended. |
2121| test.cpp:153:46:153:50 | ... = ... | Use of '=' where '==' may have been intended. |
22+ | test.cpp:160:7:160:12 | ... = ... | Use of '=' where '==' may have been intended. |
23+ | test.cpp:162:7:162:12 | ... = ... | Use of '=' where '==' may have been intended. |
24+ | test.cpp:163:7:163:12 | ... = ... | Use of '=' where '==' may have been intended. |
25+ | test.cpp:164:7:164:12 | ... = ... | Use of '=' where '==' may have been intended. |
26+ | test.cpp:166:22:166:27 | ... = ... | Use of '=' where '==' may have been intended. |
27+ | test.cpp:168:24:168:29 | ... = ... | Use of '=' where '==' may have been intended. |
28+ | test.cpp:169:23:169:28 | ... = ... | Use of '=' where '==' may have been intended. |
29+ | test.cpp:171:7:171:12 | ... = ... | Use of '=' where '==' may have been intended. |
Original file line number Diff line number Diff line change @@ -153,3 +153,21 @@ void f3(int x, int y) {
153153 if ((x == 10 ) || ((z == z) && (x == 1 )) && (y = 2 )) { // BAD
154154 }
155155}
156+
157+ bool use (int );
158+
159+ void f4 (int x, bool b) {
160+ if ((x = 10 ) && use (x)) {} // GOOD [FALSE POSITIVE]: This is likely just a short-hand way of writing an assignment
161+ // followed by a boolean check.
162+ if ((x = 10 ) && b && use (x)) {} // GOOD [FALSE POSITIVE]: Same reason as above
163+ if ((x = 10 ) && use (x) && b) {} // GOOD [FALSE POSITIVE]: Same reason as above
164+ if ((x = 10 ) && (use (x) && b)) {} // GOOD [FALSE POSITIVE]: Same reason as above
165+
166+ if (use (x) && b && (x = 10 )) {} // BAD: The assignment is the last thing that happens in the comparison.
167+ // This doesn't match the usual pattern.
168+ if ((use (x) && b) && (x = 10 )) {} // BAD: Same reason as above
169+ if (use (x) && (b && (x = 10 ))) {} // BAD: Same reason as above
170+
171+ if ((x = 10 ) || use (x)) {} // BAD: This doesn't follow the usual style of writing an assignment in
172+ // a boolean check.
173+ }
You can’t perform that action at this time.
0 commit comments