Here's the new and improved patch.

>From the ChangeLog:

2002-04-23  Duncan Mak  <[EMAIL PROTECTED]>

        * string-icalls.c (mono_string_Internal_ctor_charp_int_int):
        (mono_string_Internal_ctor_sbytep_int_int):  Removed check for
        sindex < 0, throw ArgumentOutOfRangeException instead of
        ArgumentNullException.

        Added new check for length == 0, however
        I need to make it return String.Empty from the C code.
        
        (mono_string_Internal_ctor_sbytep): 
        (mono_string_Internal_ctor_sbytep_int_int): Replaced
        mono_string_new_utf16 with mono_string_new_len, since value is  utf8.

Duncan.
Index: string-icalls.c
===================================================================
RCS file: /cvs/public/mono/mono/metadata/string-icalls.c,v
retrieving revision 1.9
diff -u -b -r1.9 string-icalls.c
--- string-icalls.c	23 Apr 2002 11:16:51 -0000	1.9
+++ string-icalls.c	24 Apr 2002 02:35:01 -0000
@@ -3,6 +3,7 @@
  *
  * Author:
  *   Patrik Torstensson ([EMAIL PROTECTED])
+ *   Duncan Mak  ([EMAIL PROTECTED])
  *
  * (C) 2001 Ximian, Inc.
  */
@@ -63,12 +64,15 @@
 	
 	domain = mono_domain_get ();
 
-	if ((value == NULL) && (sindex != 0) && (length != 0))
-		mono_raise_exception (mono_get_exception_argument_null ("Argument null"));
+	if ((value == NULL) && (length != 0))
+		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
 
 	if ((sindex < 0) || (length < 0))
 		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
 	
+	if (length == 0) 	/* fixme: return String.Empty here */
+		g_assert_not_reached ();
+	
 	begin = (gunichar2 *) (value + sindex);
 
 	return mono_string_new_utf16 (domain, begin, length);
@@ -77,38 +81,36 @@
 MonoString *
 mono_string_Internal_ctor_sbytep (gpointer dummy, gint8 *value)
 {
-	int i, length;
+	guint length;
 	MonoDomain *domain;
 	
 	domain = mono_domain_get ();
 
-	if (value == NULL)
-		length = 0;
-	else {
-		for (i = 0; *(value + i) != '\0'; i++);
-		length = i;
-	}
+	if (value == NULL) 	/* fixme: return String.Empty here */
+		g_assert_not_reached ();
+	else 
+		for (length = 0; *(value + length) != '\0'; length ++);
 
-	return mono_string_new_utf16 (domain, (gunichar2 *) value, length);
+	return mono_string_new_len (domain, (const char *) value, length);
 }
 
 MonoString *
 mono_string_Internal_ctor_sbytep_int_int (gpointer dummy, gint8 *value, gint32 sindex, gint32 length)
 {
-	gunichar2 *begin;
+	char *begin;
 	MonoDomain *domain;
 	
 	domain = mono_domain_get ();
 
-	if ((value == NULL) && (sindex != 0) && (length != 0))
-		mono_raise_exception (mono_get_exception_argument_null ("Argument null"));
+	if ((value == NULL) && (length != 0))
+		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"))
 
-	if ((sindex > 0) || (length < 0))
+	if ((sindex < 0) || (length < 0))
 		mono_raise_exception (mono_get_exception_argument_out_of_range ("Out of range"));
 
-	begin = (gunichar2 *) (value + sindex);
+	begin = (char *) (value + sindex);
 
-	return mono_string_new_utf16 (domain, begin, length);
+	return mono_string_new_len (domain, begin, length);
 }
 
 MonoString *
Index: ChangeLog
===================================================================
RCS file: /cvs/public/mono/mono/metadata/ChangeLog,v
retrieving revision 1.317
diff -u -b -r1.317 ChangeLog
--- ChangeLog	23 Apr 2002 19:44:36 -0000	1.317
+++ ChangeLog	24 Apr 2002 02:35:01 -0000
@@ -2,6 +2,20 @@
 
 	* object.c (mono_runtime_invoke_array) : Bug because of my incompetence.
 
+2002-04-23  Duncan Mak  <[EMAIL PROTECTED]>
+
+	* string-icalls.c (mono_string_Internal_ctor_charp_int_int):
+	(mono_string_Internal_ctor_sbytep_int_int):  Removed check for
+	sindex < 0, throw ArgumentOutOfRangeException instead of
+	ArgumentNullException.
+
+	Added new check for length == 0, however
+	I need to make it return String.Empty from the C code.
+	
+	(mono_string_Internal_ctor_sbytep): 
+	(mono_string_Internal_ctor_sbytep_int_int): Replaced
+	mono_string_new_utf16 with mono_string_new_len, since value is utf8.
+
 2002-04-24	Patrik Torstensson <[EMAIL PROTECTED]>
 
 	* reflection.c (mono_reflection_get_custom_attrs) : fixed image bug (crash)

Reply via email to