[Mono-list] core dump on PtrToStringUni
Aleksey Demakov
avd@openlinksw.com
Sat, 30 Nov 2002 03:15:50 +0600
Hi all,
I get "GC Warning: Out of Memory! Returning NIL!" and a core dump when
running the following program:
using System;
using System.Runtime.InteropServices;
public class Test
{
public static void Main (string[] args)
{
IntPtr buffer = Marshal.AllocHGlobal (100);
Marshal.WriteInt32 (buffer, 0);
string s = Marshal.PtrToStringUni (buffer);
Console.WriteLine ("'{0}'", s);
}
}
The fix for this is very simple:
Index: marshal.c
===================================================================
RCS file: /mono/mono/mono/metadata/marshal.c,v
retrieving revision 1.55
diff -u -r1.55 marshal.c
--- marshal.c 28 Nov 2002 12:45:45 -0000 1.55
+++ marshal.c 29 Nov 2002 21:14:37 -0000
@@ -2738,7 +2738,7 @@
MONO_ARCH_SAVE_REGS;
- while (t++)
+ while (*t++)
len++;
return mono_string_new_utf16 (domain, ptr, len);
Regards,
Aleksey