[bcl] Fix crashes when FieldInfo.GetValue () is called on a pointer field with a...
authorZoltan Varga <vargaz@gmail.com>
Fri, 2 Jan 2015 23:36:02 +0000 (18:36 -0500)
committerZoltan Varga <vargaz@gmail.com>
Fri, 2 Jan 2015 23:36:02 +0000 (18:36 -0500)
mcs/class/corlib/Test/System.Reflection/FieldInfoTest.cs
mono/metadata/object.c

index a3639864f6a48730c1e7ac06d913f4c3aa44ceb3..a7c5c2463e6d9b292ff9fd75aee26685df9ee763 100644 (file)
@@ -519,6 +519,10 @@ namespace MonoTests.System.Reflection
                [Test]
                public unsafe void GetSetValuePointers ()
                {
+                       Pointer p0 = (Pointer)typeof (FieldInfoTest).GetField ("ip").GetValue (null);
+                       int *p0i = (int*)Pointer.Unbox (p0);
+                       Assert.AreEqual (IntPtr.Zero, new IntPtr (p0i));
+
                        int i = 5;
                        void *p = &i;
                        typeof (FieldInfoTest).GetField ("ip").SetValue (null, (IntPtr)p);
index 913e94f3c3116d20d01d495fda8236f400bf0668..083112159b93794e2c4c7dc5e45d59925305a275 100644 (file)
@@ -3255,7 +3255,7 @@ mono_field_get_value_object (MonoDomain *domain, MonoClassField *field, MonoObje
                }
 
                /* MONO_TYPE_PTR is passed by value to runtime_invoke () */
-               args [0] = *ptr;
+               args [0] = ptr ? *ptr : NULL;
                args [1] = mono_type_get_object (mono_domain_get (), type);
 
                return mono_runtime_invoke (m, NULL, args, NULL);