File tree Expand file tree Collapse file tree
Best Practices/Likely Errors/EmptyBlock
Arithmetic/PointlessComparison
Likely Typos/FutileConditional Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11| empty_block.cpp:9:10:9:11 | { ... } | Empty block without comment. |
22| empty_block.cpp:12:10:13:3 | { ... } | Empty block without comment. |
33| empty_block.cpp:20:10:21:3 | { ... } | Empty block without comment. |
4+ | empty_block.cpp:84:14:85:3 | { ... } | Empty block without comment. |
5+ | empty_block.cpp:93:10:94:3 | { ... } | Empty block without comment. |
6+ | empty_block.cpp:99:10:100:3 | { ... } | Empty block without comment. |
7+ | empty_block.cpp:100:10:101:3 | { ... } | Empty block without comment. |
Original file line number Diff line number Diff line change @@ -80,5 +80,25 @@ int f(int x) {
8080 }
8181 }
8282
83+ // BAD
84+ if (x > 1 ) {
85+ }
86+
87+ // GOOD
88+ if (x) {
89+ ++x;
90+ }
91+
92+ // DUBIOUS (reported)
93+ if (x) {
94+ } else {
95+ ++x;
96+ }
97+
98+ // BAD (x2)
99+ if (x) {
100+ } else {
101+ }
102+
83103 return 1 ;
84104}
Original file line number Diff line number Diff line change @@ -43,3 +43,9 @@ int extreme_values(void)
4343 if (y >> 1 >= 0x7FFFFFFFFFFF ) {} // $ Alert[cpp/constant-comparison] // always true
4444 if (y >> 1 >= 0xFFFFFFFFFFF ) {} // $ Alert[cpp/constant-comparison] // always true
4545}
46+
47+ // Test for overlap between PointlessComparison and PointlessSelfComparison
48+ // (PointlessComparison should *not* report this)
49+ bool selfCmp1 (int x) {
50+ return (x == (int )x);
51+ }
Original file line number Diff line number Diff line change 1+ void emptyIfs (int value) {
2+ if (value) {} // $ Alert[cpp/empty-if]
3+
4+ if (value > 1 ) {
5+ } // $ Alert[cpp/empty-if]
6+
7+ if (value) { // GOOD
8+ ++value;
9+ }
10+
11+ if (value) { // GOOD
12+ } else {
13+ ++value;
14+ }
15+
16+ if (value) { // $ MISSING: Alert[cpp/empty-if]
17+ } else {
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ | FutileConditional.cpp:2:3:2:15 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
2+ | FutileConditional.cpp:4:3:5:3 | if (...) ... | If-statement with an empty then-branch and no else-branch. |
Original file line number Diff line number Diff line change 1+ query: Likely Bugs/Likely Typos/FutileConditional.ql
2+ postprocess: utils/test/InlineExpectationsTestQuery.ql
You can’t perform that action at this time.
0 commit comments