In case StringToHeap (string, Encoding) was called with a null string, it would unconditionally reference the string when trying to query the string's length.
Bug 10074 - Error while updating status of command: MonoDevelop.Ide.Commands.ViewCommands.LayoutList
public static IntPtr StringToHeap (string s, Encoding encoding)
{
+ if (s == null)
+ return IntPtr.Zero;
+
return StringToHeap (s, 0, s.Length, encoding);
}
}
#endif
+ [Test]
+ public void BXC10074 ()
+ {
+ var result = UnixMarshal.StringToHeap (null, Encoding.ASCII);
+ Assert.AreEqual (IntPtr.Zero, result, "This used to crash due to a NullReferenceException");
+ }
+
[Test]
public void TestStringToHeap ()
{