Author: kornelpal
Date: 2006-07-18 13:54:01 -0400 (Tue, 18 Jul 2006)
New Revision: 62717

Modified:
   trunk/mcs/class/corlib/System/String.cs
Log:
String.cs: Some fixes to recently added CreateString () methods.

Modified: trunk/mcs/class/corlib/System/String.cs
===================================================================
--- trunk/mcs/class/corlib/System/String.cs     2006-07-18 17:28:31 UTC (rev 
62716)
+++ trunk/mcs/class/corlib/System/String.cs     2006-07-18 17:54:01 UTC (rev 
62717)
@@ -1859,6 +1859,9 @@
 
                private unsafe String CreateString (sbyte* value)
                {
+                       if (value == null)
+                               return String.Empty;
+
                        byte* bytes = (byte*) value;
                        int length = 0;
 
@@ -1867,6 +1870,10 @@
                                        length++;
                        } catch (NullReferenceException) {
                                throw new ArgumentOutOfRangeException ("value", 
"Value does not refer to a valid string.");
+#if NET_2_0
+                       } catch (AccessViolationException) {
+                               throw new ArgumentOutOfRangeException ("value", 
"Value does not refer to a valid string.");
+#endif
                        }
 
                        return CreateString (value, 0, length, null);
@@ -1886,8 +1893,18 @@
                        if (value + startIndex < value)
                                throw new ArgumentOutOfRangeException 
("startIndex", "Value, startIndex and length do not refer to a valid string.");
 
-                       if (enc == null)
+                       bool isDefaultEncoding;
+
+                       if (isDefaultEncoding = (enc == null)) {
+                               if (value == null)
+#if NET_2_0
+                                       throw new ArgumentNullException 
("value");
+#else
+                                       return String.Empty;
+#endif
+
                                enc = Encoding.Default;
+                       }
 
                        byte [] bytes = new byte [length];
 
@@ -1896,7 +1913,19 @@
                                        try {
                                                memcpy (bytePtr, (byte*) (value 
+ startIndex), length);
                                        } catch (NullReferenceException) {
+#if !NET_2_0
+                                               if (!isDefaultEncoding)
+                                                       throw;
+#endif
+
                                                throw new 
ArgumentOutOfRangeException ("value", "Value, startIndex and length do not 
refer to a valid string.");
+#if NET_2_0
+                                       } catch (AccessViolationException) {
+                                               if (!isDefaultEncoding)
+                                                       throw;
+
+                                               throw new 
ArgumentOutOfRangeException ("value", "Value, startIndex and length do not 
refer to a valid string.");
+#endif
                                        }
 
                        // GetString () is called even when length == 0

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to