File tree Expand file tree Collapse file tree
cpp/ql/test/query-tests/Likely Bugs/Likely Typos/AssignWhereCompareMeant Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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. |
1616| test.cpp:113:6:113:10 | ... = ... | Use of '=' where '==' may have been intended. |
17+ | test.cpp:129:17:129:21 | ... = ... | Use of '=' where '==' may have been intended. |
18+ | test.cpp:134:19:134:23 | ... = ... | Use of '=' where '==' may have been intended. |
19+ | test.cpp:138:21:138:25 | ... = ... | Use of '=' where '==' may have been intended. |
20+ | test.cpp:141:7:141:11 | ... = ... | Use of '=' where '==' may have been intended. |
21+ | test.cpp:144:32:144:36 | ... = ... | Use of '=' where '==' may have been intended. |
22+ | test.cpp:147:41:147:45 | ... = ... | Use of '=' where '==' may have been intended. |
23+ | test.cpp:150:32:150:36 | ... = ... | Use of '=' where '==' may have been intended. |
24+ | test.cpp:153:46:153:50 | ... = ... | Use of '=' where '==' may have been intended. |
Original file line number Diff line number Diff line change @@ -123,4 +123,33 @@ void f2() {
123123
124124 if (sz = " def" ) { // GOOD: a == comparison with a string literal is probably not the intent here
125125 }
126+ }
127+
128+ void f3 (int x, int y) {
129+ if (x == 1 && (y = 2 )) { // GOOD [FALSE POSITIVE]: the programmer seems to be okay with unparenthesized
130+ // comparison operands, so the parenthesis was used to mark this
131+ // as an assignment
132+ }
133+
134+ if ((x == 1 ) && (y = 2 )) { // BAD
135+ }
136+
137+ long z = x;
138+ if (((z == 42 ) || (y = 2 )) && (x == 1 )) { // BAD
139+ }
140+
141+ if ((y = 2 ) && (x == z || x == 1 )) { // GOOD [FALSE POSITIVE]
142+ }
143+
144+ if (((x == 42 ) || x == 1 ) && (y = 2 )) { // BAD
145+ }
146+
147+ if (x == 10 || (x == 42 && x == 1 ) && (y = 2 )) { // GOOD [FALSE POSITIVE]
148+ }
149+
150+ if (x == 10 || ((x == 42 ) && (y = 2 )) && (z == 1 )) { // BAD
151+ }
152+
153+ if ((x == 10 ) || ((z == z) && (x == 1 )) && (y = 2 )) { // BAD
154+ }
126155}
You can’t perform that action at this time.
0 commit comments