File tree Expand file tree Collapse file tree 4 files changed +235
-154
lines changed
src/semmle/code/csharp/ir/implementation/raw/internal Expand file tree Collapse file tree 4 files changed +235
-154
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,10 @@ private predicate ignoreLoad(Expr expr) {
205205 // to get the address of the first element in an array
206206 expr = any ( ArrayAccess aa ) .getQualifier ( )
207207 or
208+ // Indexer calls returns a reference or a value,
209+ // no need to load it
210+ expr instanceof IndexerCall
211+ or
208212 // No load is needed for the lvalue in an assignment such as:
209213 // Eg. `Object obj = oldObj`;
210214 expr = any ( Assignment a ) .getLValue ( ) and
Original file line number Diff line number Diff line change 11class Events
22{
33 public delegate string MyDel ( string str ) ;
4+ public MyDel Inst ;
45
56 event MyDel MyEvent ;
67
7- public Events ( ) {
8- this . MyEvent += new MyDel ( this . WelcomeUser ) ;
8+ public Events ( )
9+ {
10+ this . Inst = new MyDel ( this . Fun ) ;
911 }
1012
11- public string WelcomeUser ( string username ) {
12- return "Welcome " + username ;
13+ public void AddEvent ( )
14+ {
15+ this . MyEvent += this . Inst ;
16+ }
17+
18+ public void RemoveEvent ( )
19+ {
20+ this . MyEvent -= this . Inst ;
21+ }
22+
23+ public string Fun ( string str )
24+ {
25+ return str ;
1326 }
1427
15- static void Main ( string [ ] args ) {
16- Events obj1 = new Events ( ) ;
17- string result = obj1 . MyEvent ( "Tutorials Point" ) ;
28+ static void Main ( string [ ] args )
29+ {
30+ Events obj = new Events ( ) ;
31+ obj . AddEvent ( ) ;
32+ string result = obj . MyEvent ( "string" ) ;
33+ obj . RemoveEvent ( ) ;
1834 }
1935}
Original file line number Diff line number Diff line change 11class Indexers
22{
3- public class Contact
3+ public class MyClass
44 {
5- private string [ ] address = new string [ 3 ] ;
5+ public MyClass ( )
6+ {
7+ }
8+
9+ private string [ ] address = new string [ 2 ] ;
610 public string this [ int index ]
711 {
812 get
@@ -18,9 +22,9 @@ public string this[int index]
1822
1923 public static void Main ( )
2024 {
21- Contact contact = new Contact ( ) ;
22- contact [ 0 ] = "Begumpet " ;
23- contact [ 1 ] = "Hyderabad " ;
24- contact [ 2 ] = "Telengana" ;
25+ MyClass inst = new MyClass ( ) ;
26+ inst [ 0 ] = "str1 " ;
27+ inst [ 1 ] = "str1 " ;
28+ inst [ 1 ] = inst [ 0 ] ;
2529 }
2630}
You can’t perform that action at this time.
0 commit comments