2001: unsafe method exception
Posted: Thu Mar 07, 2024 3:45 pm
Code: Select all
[Obfuscation(Feature = "ultra", Exclude = false)]
public unsafe class UnsafeClass
{
public void UnsafeMethod()
{
int* ptr = stackalloc int[1];
*ptr = 42;
Console.WriteLine("Unsafe method: " + *ptr);
}
}
Below works fine.
Code: Select all
public static unsafe void unsafe2()
{
Console.WriteLine("Unsafe2");
int* pointer = stackalloc int[10];
for (int i = 0; i < 10; i++)
{
pointer[i] = i;
}
Console.WriteLine($"Stackalloc result: {pointer[5]}");
}