Bug 137 - Make Ipv4Address (uint32_t) constructor explicit
Make Ipv4Address (uint32_t) constructor explicit
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: network
pre-release
All All
: P3 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-02-12 10:07 UTC by Gustavo J. A. M. Carneiro
Modified: 2008-02-15 12:18 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo J. A. M. Carneiro 2008-02-12 10:07:24 UTC
I just lost a ton of time because of an accidental implicit conversion:

Ipv4EndPoint *
Ipv4EndPointDemux::Allocate (Ipv4Address address, Ipv4Address localInterface)
{
[...]
}

Ipv4EndPoint *
Ipv4EndPointDemux::Allocate (uint16_t port)
{
  return Allocate (Ipv4Address::GetAny (), port);
}

In this case, Allocate (Ipv4Address::GetAny (), port) ends up calling Ipv4EndPointDemux::Allocate (Ipv4Address address, Ipv4Address localInterface), because the 'uint16_t port' parameter was being implicitly converted to Ipv4Address (!).  The solution is to add an 'explicit' keyword to the constructor.  It doesn't even break any existing NS-3 code.

diff -r 084b07dceafb src/node/ipv4-address.h
--- a/src/node/ipv4-address.h	Mon Feb 11 14:46:44 2008 +0000
+++ b/src/node/ipv4-address.h	Tue Feb 12 15:06:34 2008 +0000
@@ -40,7 +40,7 @@ public:
    * input address is in host order.
    * \param address The host order 32-bit address
    */
-  Ipv4Address (uint32_t address);
+  explicit Ipv4Address (uint32_t address);
   /** 
     * \brief Constructs an Ipv4Address by parsing a the input C-string
     *
Comment 1 Mathieu Lacage 2008-02-15 12:18:14 UTC
changeset 854dbe96e04c