2009-09-25 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Fri, 25 Sep 2009 20:27:56 +0000 (20:27 -0000)
committerZoltan Varga <vargaz@gmail.com>
Fri, 25 Sep 2009 20:27:56 +0000 (20:27 -0000)
* debug-helpers.c (dis_one): Avoid unaligned accesses on platforms where that is
a problem.

svn path=/trunk/mono/; revision=142657

mono/metadata/ChangeLog
mono/metadata/debug-helpers.c

index 3150b70c11746243e1855caa6cf1da9629448072..8eb8c5aad06527557673ad7ea0a94245d8a729d4 100644 (file)
@@ -1,3 +1,8 @@
+2009-09-25  Zoltan Varga  <vargaz@gmail.com>
+
+       * debug-helpers.c (dis_one): Avoid unaligned accesses on platforms where that is
+       a problem.
+
 2009-09-24  Zoltan Varga  <vargaz@gmail.com>
 
        * marshal.c (emit_ptr_to_object_conv): Generate an exception instead of
index 61883ed13d01fcd9064d16a196fc6679028380b9..d6af2541f79752016c9c32fac07bc7b580a79f0c 100644 (file)
@@ -531,6 +531,7 @@ dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned cha
                const char *blob;
                char *s;
                size_t len2;
+               char *blob2 = NULL;
 
                if (!method->klass->image->dynamic) {
                        token = read32 (ip);
@@ -539,22 +540,32 @@ dis_one (GString *str, MonoDisHelper *dh, MonoMethod *method, const unsigned cha
                        len2 = mono_metadata_decode_blob_size (blob, &blob);
                        len2 >>= 1;
 
+#ifdef NO_UNALIGNED_ACCESS
+                       /* The blob might not be 2 byte aligned */
+                       blob2 = g_malloc (len2 * 2);
+                       memcpy (blob2, blob, len2 * 2);
+#else
+                       blob2 = blob;
+#endif
+
 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
                        {
                                guint16 *buf = g_new (guint16, len2);
                                int i;
 
                                for (i = 0; i < len2; ++i)
-                                       buf [i] = GUINT16_FROM_LE (((guint16*)blob) [i]);
+                                       buf [i] = GUINT16_FROM_LE (((guint16*)blob2) [i]);
                                s = g_utf16_to_utf8 (buf, len2, NULL, NULL, NULL);
                                g_free (buf);
                        }
 #else
-                               s = g_utf16_to_utf8 ((gunichar2*)blob, len2, NULL, NULL, NULL);
+                               s = g_utf16_to_utf8 ((gunichar2*)blob2, len2, NULL, NULL, NULL);
 #endif
 
                        g_string_append_printf (str, "\"%s\"", s);
                        g_free (s);
+                       if (blob != blob2)
+                               g_free (blob2);
                }
                ip += 4;
                break;