Browse Source

[trac998] Default constructor now indicates no valid ACL

Stephen Morris 14 years ago
parent
commit
287edb431d
2 changed files with 13 additions and 7 deletions
  1. 12 1
      src/lib/acl/ip_check.h
  2. 1 6
      src/lib/acl/tests/ip_check_unittest.cc

+ 12 - 1
src/lib/acl/ip_check.h

@@ -182,6 +182,17 @@ private:
     };
     };
 
 
 public:
 public:
+    /// \brief Default Constructor
+    ///
+    /// Constructs an empty IPCheck object.  The address family returned will
+    /// be zero.
+    IPCheck() : address_(), netmask_(), masksize_(0), inverse_(false),
+                family_(0), straddr_()
+    {
+        std::fill(address_.word, address_.word + IPV6_SIZE32, 0);
+        std::fill(netmask_.word, netmask_.word + IPV6_SIZE32, 0);
+    }
+
     /// \brief IPV4 Constructor
     /// \brief IPV4 Constructor
     ///
     ///
     /// Constructs an IPCheck object from a network address given as a
     /// Constructs an IPCheck object from a network address given as a
@@ -196,7 +207,7 @@ public:
     /// \param inverse If false (the default), matches() returns true if the
     /// \param inverse If false (the default), matches() returns true if the
     ///        condition matches.  If true, matches() returns true if the
     ///        condition matches.  If true, matches() returns true if the
     ///        condition does not match.
     ///        condition does not match.
-    IPCheck(uint32_t address = 1, int masksize = 8 * sizeof(uint32_t),
+    IPCheck(uint32_t address, int masksize = 8 * sizeof(uint32_t),
             bool inverse = false):
             bool inverse = false):
             address_(), netmask_(), masksize_(masksize), inverse_(inverse),
             address_(), netmask_(), masksize_(masksize), inverse_(inverse),
             family_(AF_INET), straddr_()
             family_(AF_INET), straddr_()

+ 1 - 6
src/lib/acl/tests/ip_check_unittest.cc

@@ -149,10 +149,7 @@ TEST(IPFunctionCheck, SplitIPAddress) {
 
 
 TEST(IPCheck, DefaultConstructor) {
 TEST(IPCheck, DefaultConstructor) {
     IPCheck<GeneralAddress> acl;
     IPCheck<GeneralAddress> acl;
-
-    // The test is needed to avoid the unused variable causing a warning or
-    // getting optimised away.
-    EXPECT_EQ(AF_INET, acl.getFamily());
+    EXPECT_EQ(0, acl.getFamily());
 }
 }
 
 
 // *** IPV4 Tests ***
 // *** IPV4 Tests ***
@@ -384,8 +381,6 @@ const uint8_t MASK_128[] = {
 
 
 } // Anonymous namespace
 } // Anonymous namespace
 
 
-// Check that a default constructor can be instantiated.
-
 TEST(IPCheck, V6ConstructorAddress) {
 TEST(IPCheck, V6ConstructorAddress) {
     IPCheck<GeneralAddress> acl1(V6ADDR_1);
     IPCheck<GeneralAddress> acl1(V6ADDR_1);
     vector<uint8_t> stored = acl1.getAddress();
     vector<uint8_t> stored = acl1.getAddress();