Browse Source

[2850] Reserve names beginning with _ for internal use only

Mukund Sivaraman 12 years ago
parent
commit
cfeb578ade

+ 9 - 0
src/lib/util/memory_segment.h

@@ -171,6 +171,10 @@ public:
     /// corresponding address by that name (in such cases the real address
     /// may be different between these two processes).
     ///
+    /// Note that names beginning with an underscore ("_") are reserved
+    /// for internal use by this class. If such a name is passed to this
+    /// method, an isc::InvalidParameter exception will be thrown.
+    ///
     /// \c addr must be 0 (NULL) or an address that belongs to this segment.
     /// The latter case means it must be the return value of a previous call
     /// to \c allocate().  The actual implementation is encouraged to detect
@@ -230,6 +234,11 @@ public:
             isc_throw(InvalidParameter,
                       "NULL name is given to setNamedAddress");
         }
+        if (*name == '_') {
+            isc_throw(InvalidParameter,
+                      "Names beginning with _ are reserved for "
+                      "internal use only.");
+        }
         return (setNamedAddressImpl(name, addr));
     }
 

+ 3 - 0
src/lib/util/tests/memory_segment_common_unittest.cc

@@ -42,6 +42,9 @@ checkSegmentNamedAddress(MemorySegment& segment, bool out_of_segment_ok) {
     // NULL name isn't allowed.
     EXPECT_THROW(segment.setNamedAddress(NULL, ptr32), InvalidParameter);
 
+    // Names beginning with _ are not allowed.
+    EXPECT_THROW(segment.setNamedAddress("_foo", ptr32), InvalidParameter);
+
     // we can now get it; the stored value should be intact.
     MemorySegment::NamedAddressResult result =
         segment.getNamedAddress("test address");