GeezerVison is showing github.com — C++: Fix FP: bad Location for FieldAccess exprs · github/codeql@96c73bc
File tree
Expand file treeCollapse file tree
Open diff view settings
src/Best Practices/Likely Errors test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.ql +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,9 +16,12 @@ Expr normalizeExpr(Expr e) { |
16 | 16 | if exists(e.(Call).getQualifier()) |
17 | 17 | then result = normalizeExpr(e.(Call).getQualifier()) |
18 | 18 | else |
19 | | - if e.hasExplicitConversion() |
20 | | - then result = normalizeExpr(e.getFullyConverted()) |
21 | | - else result = e |
| 19 | + if exists(e.(FieldAccess).getQualifier()) |
| 20 | + then result = normalizeExpr(e.(FieldAccess).getQualifier()) |
| 21 | + else |
| 22 | + if e.hasExplicitConversion() |
| 23 | + then result = normalizeExpr(e.getFullyConverted()) |
| 24 | + else result = e |
22 | 25 | } |
23 | 26 |
|
24 | 27 | predicate isInLoopHead(CommaExpr ce) { |
|
45 | 48 | not isInDecltypeOrSizeof(ce) and // <- Removes arguable FPs since, like function calls (and loop heads), these Exprs have clear delimiters. |
46 | 49 | leftLoc.getEndLine() < rightLoc.getStartLine() and |
47 | 50 | leftLoc.getStartColumn() > rightLoc.getStartColumn() |
48 | | -select right, "The indentation after the comma may be misleading (for some tab sizes)." |
| 51 | +select right, "The indentation level may be misleading (for some tab sizes)." |
Collapse file
Copy file name to clipboardExpand all lines: cpp/ql/test/query-tests/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation/test.cpp +13-2Lines changed: 13 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -122,15 +122,26 @@ int test(int i, int j, int (*foo)(int), int (*bar)(int, int)) |
122 | 122 | i++ |
123 | 123 | ), j++); // GOOD? |
124 | 124 |
|
125 | | - // Weird case: |
| 125 | + // Weird cases: |
126 | 126 |
|
127 | 127 | if (foo(j)) |
128 | 128 | return i++ |
129 | 129 | , i++ // GOOD(?) [FALSE POSITIVE] -- can't exclude w/o source code text :/ |
130 | 130 | ? 1 |
131 | 131 | : 2; |
132 | 132 |
|
133 | | - return 0; |
| 133 | + struct { |
| 134 | + struct { |
| 135 | + void tutu() {} |
| 136 | + long toto() { return 42; } |
| 137 | + } titi; |
| 138 | + } *tata; |
| 139 | + |
| 140 | + int quux = |
| 141 | + (tata->titi.tutu(), |
| 142 | + foo(tata->titi.toto())); // GOOD |
| 143 | + |
| 144 | + return quux; |
134 | 145 | } |
135 | 146 |
|
136 | 147 | // Comma in variadic template splice: |
|