Use return value of the function instead of a pointer to the target.
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 12 Dec 2011 14:02:47 +0000 (15:02 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 12 Dec 2011 14:02:47 +0000 (15:02 +0100)
C++ will automatically create a copy of the object upon return.

src/dns/dnsresolver.cpp
src/dns/dnsresolver.h

index 3eda24a..cb45850 100644 (file)
@@ -88,8 +88,7 @@ bool DnsResolver::resolve()
 
     try
     {
-        rr_list_t answers_list;
-        fill_answers_list( HostDnsAddress, NameServer, &answers_list );
+        rr_list_t answers_list = fill_answers_list( HostDnsAddress, NameServer);
 
         int resolved_ip_count = answers_list.size();
         if ( resolved_ip_count < 1 )
@@ -218,24 +217,22 @@ bool DnsResolver::handle_ip_address()
     return false;
 }
 
-void DnsResolver::fill_answers_list(
+rr_list_t DnsResolver::fill_answers_list(
         const string &host_dns_address,
-        const string &name_server,
-        rr_list_t *answers_list
-)
+        const string &name_server)
 {
+    rr_list_t answer_list;
+
     BOOST_ASSERT( !host_dns_address.empty() );
     BOOST_ASSERT( !name_server.empty() );
-    BOOST_ASSERT( answers_list != NULL );
 
     address nameServer( address::from_string( name_server ) );
     boost::net::dns::resolve resolver;
     resolver.addServer( nameServer );
     message dns_message( host_dns_address, boost::net::dns::type_a );
     message& dns_packet = resolver.query( dns_message );
-    // Note: perform a copy of each element from one vector to the other, do
-    // not reference
-    *answers_list = *dns_packet.answers();
+    // Note: perform a copy of each element from one vector to the other, do not reference
+    return *dns_packet.answers();
 }
 
 void DnsResolver::fill_resolved_ip_list(
index abc82e1..030c3e2 100644 (file)
@@ -51,10 +51,9 @@ public:
 private:
     bool handle_ip_address();
 
-    void fill_answers_list(
+    boost::net::dns::rr_list_t fill_answers_list(
             const std::string &host_dns_address,
-            const std::string &name_server,
-            boost::net::dns::rr_list_t *answers_list
+            const std::string &name_server
     );
     void fill_resolved_ip_list(
             const boost::net::dns::rr_list_t& answers_list,