mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Test example with ref local, unsafe context and ref struct in async and iterator methods.
This commit is contained in:
@@ -12,3 +12,6 @@
|
||||
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | async |
|
||||
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | private |
|
||||
| async.cs:50:49:50:57 | OpenAsync | file://:0:0:0:0 | static |
|
||||
| async.cs:64:40:64:53 | GetObjectAsync | file://:0:0:0:0 | async |
|
||||
| async.cs:64:40:64:53 | GetObjectAsync | file://:0:0:0:0 | private |
|
||||
| async.cs:64:40:64:53 | GetObjectAsync | file://:0:0:0:0 | static |
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
| 42 | async.cs:42:46:42:70 | await ... | async.cs:42:52:42:70 | call to method OpenAsync |
|
||||
| 44 | async.cs:44:38:44:66 | await ... | async.cs:44:44:44:66 | call to method ReadToEndAsync |
|
||||
| 52 | async.cs:52:13:52:51 | await ... | async.cs:52:19:52:51 | call to method PrintContentLengthAsync |
|
||||
| 73 | async.cs:73:13:73:31 | await ... | async.cs:73:19:73:31 | call to method Delay |
|
||||
|
||||
@@ -52,5 +52,26 @@ namespace Semmle
|
||||
await PrintContentLengthAsync(filename);
|
||||
return File.OpenText(filename);
|
||||
}
|
||||
|
||||
private ref struct RS
|
||||
{
|
||||
public int GetZero() { return 0; }
|
||||
}
|
||||
|
||||
private static int one = 1;
|
||||
|
||||
// Test that we can use ref locals, ref structs and unsafe blocks in async methods.
|
||||
private static async Task<int> GetObjectAsync()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
// Do pointer stuff
|
||||
}
|
||||
RS rs;
|
||||
ref int i = ref one;
|
||||
var zero = rs.GetZero();
|
||||
await Task.Delay(i);
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
25
csharp/ql/test/library-tests/iterators/iterators.cs
Normal file
25
csharp/ql/test/library-tests/iterators/iterators.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public ref struct RS
|
||||
{
|
||||
public int GetZero() { return 0; }
|
||||
}
|
||||
|
||||
public class C
|
||||
{
|
||||
private int one = 1;
|
||||
|
||||
// Test that we can use unsafe context, ref locals and ref structs in iterators.
|
||||
public IEnumerable<int> GetObjects()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
// Do pointer stuff
|
||||
}
|
||||
ref int i = ref one;
|
||||
RS rs;
|
||||
var zero = rs.GetZero();
|
||||
yield return zero;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
| iterators.cs:14:29:14:38 | GetObjects | iterators.cs:23:22:23:25 | access to local variable zero |
|
||||
5
csharp/ql/test/library-tests/iterators/iterators.ql
Normal file
5
csharp/ql/test/library-tests/iterators/iterators.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import csharp
|
||||
|
||||
from Callable c, Expr return
|
||||
where c.canYieldReturn(return)
|
||||
select c, return
|
||||
Reference in New Issue
Block a user