| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,12 +11,35 @@ | |||
| 11 | 11 | import cpp | |
| 12 | 12 | import semmle.code.cpp.commons.Exclusions | |
| 13 | 13 | ||
| 14 | + /** | ||
| 15 | + * Holds if this is an implicit `this`. | ||
| 16 | + * | ||
| 17 | + * ThisExpr.isCompilerGenerated() is currently not being extracted, so use a heuristic. | ||
| 18 | + */ | ||
| 19 | + predicate isCompilerGenerated(ThisExpr te) { | ||
| 20 | + exists( | ||
| 21 | + string filepath, int line, int colStart, int colEnd, boolean zeroDiff, boolean sameLocAsCall | ||
| 22 | + | | ||
| 23 | + te.getLocation().hasLocationInfo(filepath, line, colStart, line, colEnd) and | ||
| 24 | + (if colStart = colEnd then zeroDiff = true else zeroDiff = false) and | ||
| 25 | + ( | ||
| 26 | + if exists(Call c | c.getQualifier() = te | c.getLocation() = te.getLocation()) | ||
| 27 | + then sameLocAsCall = true | ||
| 28 | + else sameLocAsCall = false | ||
| 29 | + ) | ||
| 30 | + | | ||
| 31 | + zeroDiff = true | ||
| 32 | + or | ||
| 33 | + zeroDiff = false and sameLocAsCall = true | ||
| 34 | + ) | ||
| 35 | + } | ||
| 36 | + | ||
| 14 | 37 | /** Gets the sub-expression of 'e' with the earliest-starting Location */ | |
| 15 | 38 | Expr normalizeExpr(Expr e) { | |
| 16 | - if forex(Expr q | q = e.(Call).getQualifier() | not q.(ThisExpr).isCompilerGenerated()) | ||
| 39 | + if forex(Expr q | q = e.(Call).getQualifier() | not isCompilerGenerated(q.(ThisExpr))) | ||
| 17 | 40 | then result = normalizeExpr(e.(Call).getQualifier()) | |
| 18 | 41 | else | |
| 19 | - if forex(Expr q | q = e.(FieldAccess).getQualifier() | not q.(ThisExpr).isCompilerGenerated()) | ||
| 42 | + if forex(Expr q | q = e.(FieldAccess).getQualifier() | not isCompilerGenerated(q.(ThisExpr))) | ||
| 20 | 43 | then result = normalizeExpr(e.(FieldAccess).getQualifier()) | |
| 21 | 44 | else | |
| 22 | 45 | if e.hasExplicitConversion() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,7 @@ struct X { | |||
| 16 | 16 | #define BAZ //printf | |
| 17 | 17 | ||
| 18 | 18 | struct Foo { | |
| 19 | - int i; | ||
| 19 | + int i, i_array[3]; | ||
| 20 | 20 | int j; | |
| 21 | 21 | virtual int foo(int) = 0; | |
| 22 | 22 | virtual int bar(int, int) = 0; | |
@@ -27,9 +27,9 @@ struct Foo { | |||
| 27 | 27 | void tutu() {} | |
| 28 | 28 | long toto() { return 42; } | |
| 29 | 29 | } titi; | |
| 30 | - } *tata; | ||
| 31 | 30 | ||
| 32 | - Tata::Titi **titi_ptr_ptr; | ||
| 31 | + Titi *operator->() { return &titi; } | ||
| 32 | + } *tata; | ||
| 33 | 33 | }; | |
| 34 | 34 | ||
| 35 | 35 | int Foo::test(int (*baz)(int)) | |
@@ -38,7 +38,7 @@ int Foo::test(int (*baz)(int)) | |||
| 38 | 38 | ||
| 39 | 39 | if (i) | |
| 40 | 40 | (void)i, // GOOD | |
| 41 | - (void)j; | ||
| 41 | + j++; | ||
| 42 | 42 | ||
| 43 | 43 | if (i) | |
| 44 | 44 | this->foo(i), // GOOD | |
@@ -181,8 +181,8 @@ int Foo::test(int (*baz)(int)) | |||
| 181 | 181 | (tata->titi.tutu(), | |
| 182 | 182 | foo(tata->titi.toto())); // GOOD | |
| 183 | 183 | ||
| 184 | - (*titi_ptr_ptr)->tutu(), // GOOD | ||
| 185 | - (&i)[0] += (int)(*titi_ptr_ptr)->toto(); | ||
| 184 | + (*tata)->toto(), // GOOD | ||
| 185 | + i_array[i] += (int)(*tata)->toto(); | ||
| 186 | 186 | ||
| 187 | 187 | return quux; | |
| 188 | 188 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments