Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by [EMAIL PROTECTED]

http://bugzilla.ximian.com/show_bug.cgi?id=79744

--- shadow/79744        2006-10-26 14:05:51.000000000 -0400
+++ shadow/79744.tmp.27028      2006-10-26 14:05:51.000000000 -0400
@@ -0,0 +1,63 @@
+Bug#: 79744
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: JIT
+AssignedTo: [EMAIL PROTECTED]                            
+ReportedBy: [EMAIL PROTECTED]               
+QAContact: [EMAIL PROTECTED]
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Invalid code that breaks the runtime.
+
+Code that uses unaligned offsets for objects can break the runtime, we
+should instead throw a TypeLoadException:
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Z {
+    ~Z() {
+        Console.WriteLine("Hello, world!");
+    }
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct X {
+    [FieldOffset(0)] public short a;
+    [FieldOffset(2)] public Z z; // Unaligned reference
+}
+
+class Y {
+    static X test() {
+        X x = new X();
+        x.z = new Z();
+        return x;
+    }
+
+    static void test2(X x) {
+        Console.WriteLine("Object: " + x);
+    }
+
+    static void Main() {
+        X t1 = test();
+        System.GC.Collect();
+        System.GC.Collect();
+        System.GC.WaitForPendingFinalizers();
+        test2(t1);
+    }
+}
+
+MS results:
+
+Unhandled Exception: System.TypeLoadException: Could not load type X from
+assembly a, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null because
+it contains an object field at offset 2 that is incorrectly aligned or
+overlapped by a non-object field.
+   at Y.Main()
_______________________________________________
mono-bugs maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-bugs

Reply via email to