--------------------- PatchSet 6172 Date: 2007/11/22 23:22:40 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Add copy-constructor for IPAddress* pointers. This constructor performs some pointer-safety checks for NULL and dynamic conversion before de-referencing and taking a COPY of the data. This does not keep any reference to the original pointer. Code calling this constructor must perform any and all needed memory-management on the pointer itself. Members: include/IPAddress.h:1.1.2.40->1.1.2.41 lib/IPAddress.cc:1.1.2.73->1.1.2.74 Index: squid3/include/IPAddress.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/include/Attic/IPAddress.h,v retrieving revision 1.1.2.40 retrieving revision 1.1.2.41 diff -u -r1.1.2.40 -r1.1.2.41 --- squid3/include/IPAddress.h 28 Oct 2007 11:27:56 -0000 1.1.2.40 +++ squid3/include/IPAddress.h 22 Nov 2007 23:22:40 -0000 1.1.2.41 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.h,v 1.1.2.40 2007/10/28 11:27:56 amosjeffries Exp $ + * $Id: IPAddress.h,v 1.1.2.41 2007/11/22 23:22:40 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -89,10 +89,18 @@ public: /** @name Constructors and Destructor */ /*@{*/ - // default constructor. IPAddress(); IPAddress(const IPAddress &); + /** + * This constructor takes its own copy of the object pointed to for memory-safe usage later. + * The caller must itself perform and ptr memory-management needed. + * + \deprecated Use of pointers can be nasty. Consider this a last-resort. + * Prefer the by-reference (&) version instead. + */ + IPAddress(const IPAddress *); + IPAddress(const struct in_addr &); IPAddress(const struct sockaddr_in &); Index: squid3/lib/IPAddress.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/lib/Attic/IPAddress.cc,v retrieving revision 1.1.2.73 retrieving revision 1.1.2.74 diff -u -r1.1.2.73 -r1.1.2.74 --- squid3/lib/IPAddress.cc 31 Oct 2007 04:51:38 -0000 1.1.2.73 +++ squid3/lib/IPAddress.cc 22 Nov 2007 23:22:40 -0000 1.1.2.74 @@ -1,5 +1,5 @@ /* - * $Id: IPAddress.cc,v 1.1.2.73 2007/10/31 04:51:38 amosjeffries Exp $ + * $Id: IPAddress.cc,v 1.1.2.74 2007/11/22 23:22:40 amosjeffries Exp $ * * DEBUG: section 14 IP Storage and Handling * AUTHOR: Amos Jeffries @@ -633,6 +633,16 @@ operator=(s); } +IPAddress::IPAddress(const IPAddress *s) +{ + IPAddress *tmp = NULL; + SetEmpty(); + if(!s) return; + tmp = dynamic_cast(s); + if(!tmp) return; + operator=(*tmp); +} + IPAddress::IPAddress(const struct hostent &s) { SetEmpty();