[Mono-bugs] [Bug 78703][Nor] Changed - String constructors that take sbyte* should use Encoding.Default rather than UTF-8 and Latin-1

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Jul 15 17:14:09 EDT 2006


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 kornelpal at gmail.com.

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

--- shadow/78703	2006-07-15 17:04:09.000000000 -0400
+++ shadow/78703.tmp.26917	2006-07-15 17:14:09.000000000 -0400
@@ -53,6 +53,28 @@
 Unamanged code (.c files) differ in that the second one uses a 
 wrapper while the first one directly maps .ctor to CreateString.
 
 Note that the first patch was approved by Zoltán while the second 
 one was not commented by anyone yet. I'm waiting for his response 
 which marshal.c code of these two does he prefer.
+
+------- Additional Comments From kornelpal at gmail.com  2006-07-15 17:14 -------
+A test is as easy as calling the constructor with a pointer. I'll 
+provide a test but because it uses Encoding.Default (that is CP_ACP 
+or GetACP() on Windows) both the actual and the expected result 
+depend on the selected ANSI code page.
+
+string s = "something\0";
+byte[] b = Encoding.Default.GetBytes(s);
+
+fixed (byte* p = b) {
+	Console.WriteLine(new string((sbyte*)p));
+	Console.WriteLine(new string((sbyte*)p, 0, b.Length));
+}
+
+Note that you should use some string that is specific to the ANSI 
+encoding instead of "something" to verify that these constructors 
+use ANSI code page. NULL termination is required by the first 
+constructor.
+
+The above referenced MSDN documentation verifies this behavior as 
+well.


More information about the mono-bugs mailing list