]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1266] addressed review
authorRazvan Becheriu <razvan@isc.org>
Fri, 5 Jun 2020 10:19:22 +0000 (13:19 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 5 Jun 2020 10:19:22 +0000 (13:19 +0300)
src/lib/log/logger.h
src/lib/log/logger_impl.h

index d615ec4171468a4e0dafd79ed93e8f39d6cc774a..40c8393e0203a7f97bf0a54588a31e0c5bfa6f91 100644 (file)
@@ -81,13 +81,14 @@ class InterprocessSync;
 /// the string passed to the Logger constructor) to a maximum of 31 characters.
 /// There is no reason for this particular value other than limiting the amount
 /// of memory used.  It is defined by the constant Logger::MAX_LOGGER_NAME_SIZE,
-/// and can be made larger (or smaller) if so desired.
+/// and can be made larger (or smaller) if so desired.  Note however, using a
+/// logger name larger than this limit will cause an assertion failure.
 
 class LoggerImpl;   // Forward declaration of the implementation class
 
 /// \brief Bad Interprocess Sync
 ///
-/// Exception thrown if a bad InterprocessSync object (such as NULL) is
+/// Exception thrown if a bad InterprocessSync object (such as null) is
 /// used.
 class BadInterprocessSync : public isc::Exception {
 public:
@@ -106,7 +107,7 @@ public:
     {}
 };
 
-/// \brief Logger Name is Null
+/// \brief Logger Name is null
 ///
 /// Exception thrown if a logger name is null
 class LoggerNameNull : public isc::Exception {
@@ -164,10 +165,7 @@ public:
     Logger(const char* name) : loggerptr_(), initialized_(false) {
 
         // Validate the name of the logger.
-        if (name == NULL) {
-            isc_throw(LoggerNameNull, "logger names may not be null");
-
-        } else {
+        if (name) {
             // Name not null, is it too short or too long?
             size_t namelen = std::strlen(name);
             if ((namelen == 0) || (namelen > MAX_LOGGER_NAME_SIZE)) {
@@ -176,9 +174,17 @@ public:
                           << "and " << MAX_LOGGER_NAME_SIZE << " characters in "
                           << "length");
             }
+        } else {
+            isc_throw(LoggerNameNull, "logger names may not be null");
         }
 
-        // Do the copy, ensuring a trailing NULL in all cases.
+        // The checks above and the assertion below ensure that the contents of
+        // "name" plus a trailing null will fit into the space allocated for
+        // "name_".
+        static_assert(MAX_LOGGER_NAME_SIZE < sizeof(name_));
+
+
+        // Do the copy, ensuring a trailing null in all cases.
         std::strncpy(name_, name, MAX_LOGGER_NAME_SIZE);
         name_[MAX_LOGGER_NAME_SIZE] = '\0';
     }
@@ -282,7 +288,7 @@ public:
 
     /// \brief Replace the interprocess synchronization object
     ///
-    /// If this method is called with NULL as the argument, it throws a
+    /// If this method is called with null as the argument, it throws a
     /// BadInterprocessSync exception.
     ///
     /// \note This method is intended to be used only within this log library
@@ -292,7 +298,7 @@ public:
     ///
     /// \param sync The logger uses this synchronization object for
     /// synchronizing output of log messages. It should be deletable and
-    /// the ownership is transferred to the logger. If NULL is passed,
+    /// the ownership is transferred to the logger. If null is passed,
     /// a BadInterprocessSync exception is thrown.
     void setInterprocessSync(isc::log::interprocess::InterprocessSync* sync);
 
index 9e1fae74979b5c2d8edf6578b2a86f1a29750d4f..7cd3f71ea362c13c9d06f8b5a2a3cf0d01dccf17 100644 (file)
@@ -194,6 +194,7 @@ private:
     isc::log::interprocess::InterprocessSync* sync_;
 };
 
+/// \brief Pointer to the Logger implementation.
 typedef boost::shared_ptr<LoggerImpl> LoggerImplPtr;
 
 } // namespace log