Hi list,

I just commited the attached patch to merge some cloning fixes from gcj
to classpath.


Michael


2005-04-26  David Daney  <[EMAIL PROTECTED]>

        * java/net/InetAddress.java (InetAddress): Make a private copy of
        the address.
        * java/net/Inet4Address.java (getAddress): Return a copy of the
        address.
        * java/net/Inet6Address.java (Inet6Address): Use private copy of
        the address
        (getAddress): Return a copy of the address.
        (equals): Rewrote.

Index: java/net/Inet4Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet4Address.java,v
retrieving revision 1.14
diff -u -r1.14 Inet4Address.java
--- java/net/Inet4Address.java  11 Jan 2005 09:44:32 -0000      1.14
+++ java/net/Inet4Address.java  26 Apr 2005 07:43:52 -0000
@@ -180,7 +180,7 @@
    */
   public byte[] getAddress()
   {
-    return addr;
+    return (byte[]) addr.clone();
   }
 
   /**
Index: java/net/Inet6Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet6Address.java,v
retrieving revision 1.9
diff -u -r1.9 Inet6Address.java
--- java/net/Inet6Address.java  14 Nov 2004 20:44:48 -0000      1.9
+++ java/net/Inet6Address.java  26 Apr 2005 07:43:52 -0000
@@ -65,7 +65,8 @@
   Inet6Address(byte[] addr, String host)
   {
     super(addr, host);
-    this.ipaddress = addr;
+    // Super constructor clones the addr.  Get a reference to the clone.
+    this.ipaddress = this.addr;
   }
 
   /**
@@ -194,7 +195,7 @@
    */
   public byte[] getAddress()
   {
-    return ipaddress;
+    return (byte[]) ipaddress.clone();
   }
 
   /**
@@ -233,9 +234,10 @@
     if (! (obj instanceof Inet6Address))
       return false;
 
-    Inet6Address tmp = (Inet6Address) obj;
-
-    return super.equals(tmp) && this.ipaddress == tmp.ipaddress;
+    // this.ipaddress is never set in this class except to
+    // the value of the super class' addr.  The super classes
+    // equals(Object) will do the compare.
+    return super.equals(obj);
   }
 
   /**
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/InetAddress.java,v
retrieving revision 1.39
diff -u -r1.39 InetAddress.java
--- java/net/InetAddress.java   11 Apr 2005 18:58:38 -0000      1.39
+++ java/net/InetAddress.java   26 Apr 2005 07:43:52 -0000
@@ -197,12 +197,9 @@
    */
   InetAddress(byte[] ipaddr, String hostname)
   {
-    addr = new byte[ipaddr.length];
-
-    for (int i = 0; i < ipaddr.length; i++)
-      addr[i] = ipaddr[i];
-
-    this.hostName = hostname;
+    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
+    hostName = hostname;
+    
     lookup_time = System.currentTimeMillis();
 
     family = 2; /* AF_INET */
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to