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) {
205
205
// to get the address of the first element in an array
206
206
expr = any ( ArrayAccess aa ) .getQualifier ( )
207
207
or
208
+ // Indexer calls returns a reference or a value,
209
+ // no need to load it
210
+ expr instanceof IndexerCall
211
+ or
208
212
// No load is needed for the lvalue in an assignment such as:
209
213
// Eg. `Object obj = oldObj`;
210
214
expr = any ( Assignment a ) .getLValue ( ) and
Original file line number Diff line number Diff line change 1
1
class Events
2
2
{
3
3
public delegate string MyDel ( string str ) ;
4
+ public MyDel Inst ;
4
5
5
6
event MyDel MyEvent ;
6
7
7
- public Events ( ) {
8
- this . MyEvent += new MyDel ( this . WelcomeUser ) ;
8
+ public Events ( )
9
+ {
10
+ this . Inst = new MyDel ( this . Fun ) ;
9
11
}
10
12
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 ;
13
26
}
14
27
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 ( ) ;
18
34
}
19
35
}
Original file line number Diff line number Diff line change 1
1
class Indexers
2
2
{
3
- public class Contact
3
+ public class MyClass
4
4
{
5
- private string [ ] address = new string [ 3 ] ;
5
+ public MyClass ( )
6
+ {
7
+ }
8
+
9
+ private string [ ] address = new string [ 2 ] ;
6
10
public string this [ int index ]
7
11
{
8
12
get
@@ -18,9 +22,9 @@ public string this[int index]
18
22
19
23
public static void Main ( )
20
24
{
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 ] ;
25
29
}
26
30
}
You can’t perform that action at this time.
0 commit comments