BIND 10 master, updated. 616537c54eb13b434294342e1a0df06375134ec0 Merge branch 'master' into trac1025
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jul 7 17:08:58 UTC 2011
The branch, master has been updated
via 616537c54eb13b434294342e1a0df06375134ec0 (commit)
via 7c7238ca556654cd2a0483dab5e7478fa7956a88 (commit)
from b5bbfb2f868f8f7401018debe275c39fc65a5139 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 616537c54eb13b434294342e1a0df06375134ec0
Merge: 7c7238ca556654cd2a0483dab5e7478fa7956a88 b5bbfb2f868f8f7401018debe275c39fc65a5139
Author: Stephen Morris <stephen at isc.org>
Date: Thu Jul 7 17:58:32 2011 +0100
Merge branch 'master' into trac1025
commit 7c7238ca556654cd2a0483dab5e7478fa7956a88
Author: Stephen Morris <stephen at isc.org>
Date: Thu Jul 7 11:38:39 2011 +0100
[trac1025] Handle possible bad_lexical_cast exception in Formatter::arg()
-----------------------------------------------------------------------
Summary of changes:
src/lib/log/log_formatter.h | 32 +++++++++++++++++++++++++++++++-
src/lib/log/tests/Makefile.am | 2 ++
2 files changed, 33 insertions(+), 1 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/log/log_formatter.h b/src/lib/log/log_formatter.h
index 11dec84..ca23844 100644
--- a/src/lib/log/log_formatter.h
+++ b/src/lib/log/log_formatter.h
@@ -18,12 +18,28 @@
#include <cstddef>
#include <string>
#include <iostream>
+
+#include <exceptions/exceptions.h>
#include <boost/lexical_cast.hpp>
#include <log/logger_level.h>
namespace isc {
namespace log {
+/// \brief Format Failure
+///
+/// This exception is used to wrap a bad_lexical_cast exception thrown during
+/// formatting an argument.
+
+class FormatFailure : public isc::Exception {
+public:
+ FormatFailure(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what)
+ {}
+};
+
+
+///
/// \brief The internal replacement routine
///
/// This is used internally by the Formatter. Replaces a placeholder
@@ -156,7 +172,21 @@ public:
/// \param arg The argument to place into the placeholder.
template<class Arg> Formatter& arg(const Arg& value) {
if (logger_) {
- return (arg(boost::lexical_cast<std::string>(value)));
+ try {
+ return (arg(boost::lexical_cast<std::string>(value)));
+ } catch (const boost::bad_lexical_cast& ex) {
+
+ // A bad_lexical_cast during a conversion to a string is
+ // *extremely* unlikely to fail. However, there is nothing
+ // in the documentation that rules it out, so we need to handle
+ // it. As it is a potentially very serious problem, throw the
+ // exception detailing the problem with as much information as
+ // we can. (Note that this does not include 'value' -
+ // boost::lexical_cast failed to convert it to a string, so an
+ // attempt to do so here would probably fail as well.)
+ isc_throw(FormatFailure, "bad_lexical_cast in call to "
+ "Formatter::arg(): " << ex.what());
+ }
} else {
return (*this);
}
diff --git a/src/lib/log/tests/Makefile.am b/src/lib/log/tests/Makefile.am
index 6159d63..069a7b4 100644
--- a/src/lib/log/tests/Makefile.am
+++ b/src/lib/log/tests/Makefile.am
@@ -51,6 +51,7 @@ logger_example_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
logger_example_LDFLAGS = $(AM_LDFLAGS) $(LOG4CPLUS_LDFLAGS)
logger_example_LDADD = $(top_builddir)/src/lib/log/liblog.la
logger_example_LDADD += $(top_builddir)/src/lib/util/libutil.la
+logger_example_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
check_PROGRAMS += init_logger_test
init_logger_test_SOURCES = init_logger_test.cc
@@ -58,6 +59,7 @@ init_logger_test_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
init_logger_test_LDFLAGS = $(AM_LDFLAGS) $(LOG4CPLUS_LDFLAGS)
init_logger_test_LDADD = $(top_builddir)/src/lib/log/liblog.la
init_logger_test_LDADD += $(top_builddir)/src/lib/util/libutil.la
+init_logger_test_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
noinst_PROGRAMS = $(TESTS)
More information about the bind10-changes
mailing list