Author: raja
Date: 2005-04-04 07:31:34 -0400 (Mon, 04 Apr 2005)
New Revision: 42510

Modified:
   trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog
   trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
Log:
(Dictionary.CopyTo, HashKeyCollection.CopyTo, HashValueCollection.CopyTo):
Add some argument checks.


Modified: trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog 2005-04-04 
11:23:49 UTC (rev 42509)
+++ trunk/mcs/class/corlib/System.Collections.Generic/ChangeLog 2005-04-04 
11:31:34 UTC (rev 42510)
@@ -6,6 +6,8 @@
        the index of the chain suitable for/containing the key.
        (Item, Add, Remove): Simplify, and remove FIXMEs.
        (Resize): Reuse linked list nodes from old table.
+       (Dictionary.CopyTo, HashKeyCollection.CopyTo, 
HashValueCollection.CopyTo):
+       Add some argument checks.
 
 2005-04-02  Ben Maurer  <[EMAIL PROTECTED]>
 

Modified: trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs
===================================================================
--- trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs     
2005-04-04 11:23:49 UTC (rev 42509)
+++ trunk/mcs/class/corlib/System.Collections.Generic/Dictionary.cs     
2005-04-04 11:31:34 UTC (rev 42510)
@@ -199,12 +199,17 @@
        
                void CopyTo (KeyValuePair<K, V> [] array, int index)
                {
-                       if (array.Length > _usedSlots)
+                       if (array == null)
+                               throw new ArgumentNullException ("array");
+                       if (index < 0)
+                               throw new ArgumentOutOfRangeException ("index");
+                       if (index >= array.Length)
+                               throw new ArgumentException ("index larger than 
largest valid index of array");
+                       if (array.Length - index < _usedSlots)
                                throw new ArgumentException ("Destination array 
cannot hold the requested elements!");
                        
-                       int i = 0;
                        foreach (KeyValuePair<K, V> kv in this)
-                               array [i++] = kv;
+                               array [index++] = kv;
                }
        
                protected void Resize ()
@@ -635,10 +640,18 @@
        
                        public void CopyTo (K [] array, int index)
                        {
+                               if (array == null)
+                                       throw new ArgumentNullException 
("array");
+                               if (index < 0)
+                                       throw new ArgumentOutOfRangeException 
("index");
+                               if (index >= array.Length)
+                                       throw new ArgumentException ("index 
larger than largest valid index of array");
+                               if (array.Length - index < 
_dictionary._usedSlots)
+                                       throw new ArgumentException 
("Destination array cannot hold the requested elements!");
+
                                IEnumerable<K> enumerateThis = (IEnumerable<K>) 
this;
-                               int i = 0;
                                foreach (K k in enumerateThis) {
-                                       array [i++] = k;
+                                       array [index++] = k;
                                }
                        }
        
@@ -734,10 +747,18 @@
        
                        public void CopyTo (V [] array, int index)
                        {
+                               if (array == null)
+                                       throw new ArgumentNullException 
("array");
+                               if (index < 0)
+                                       throw new ArgumentOutOfRangeException 
("index");
+                               if (index >= array.Length)
+                                       throw new ArgumentException ("index 
larger than largest valid index of array");
+                               if (array.Length - index < 
_dictionary._usedSlots)
+                                       throw new ArgumentException 
("Destination array cannot hold the requested elements!");
+
                                IEnumerable<V> enumerateThis = (IEnumerable<V>) 
this;
-                               int i = 0;
                                foreach (V v in enumerateThis) {
-                                       array [i++] = v;
+                                       array [index++] = v;
                                }
                        }
        

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

Reply via email to