From e58c97a735c8ce048a01045c67899f458f02ce17 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 19 Nov 2015 00:05:08 +0100 Subject: [PATCH 1/2] [4203] Removed the unreachable exit --- src/lib/eval/lexer.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/eval/lexer.ll b/src/lib/eval/lexer.ll index ce20911a6a..71d5eaab03 100644 --- a/src/lib/eval/lexer.ll +++ b/src/lib/eval/lexer.ll @@ -145,7 +145,7 @@ EvalContext::scanStringBegin() buffer = yy_scan_bytes(string_.c_str(), string_.size()); if (!buffer) { error("cannot scan string"); - exit(EXIT_FAILURE); + // error throws an exception so this can't be reached } } From 3d663ac34a7680efae66ca9dfc2d279a86e66186 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Thu, 19 Nov 2015 00:52:57 +0100 Subject: [PATCH 2/2] [4203] Added new fatal class method for yy_fatal_error fix --- src/lib/eval/eval_context.cc | 6 ++++++ src/lib/eval/eval_context.h | 5 +++++ src/lib/eval/lexer.ll | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib/eval/eval_context.cc b/src/lib/eval/eval_context.cc index 7dc46fc4cc..99cc4e085c 100644 --- a/src/lib/eval/eval_context.cc +++ b/src/lib/eval/eval_context.cc @@ -50,3 +50,9 @@ EvalContext::error (const std::string& what) { isc_throw(EvalParseError, what); } + +void +EvalContext::fatal (const std::string& what) +{ + isc_throw(Unexpected, what); +} diff --git a/src/lib/eval/eval_context.h b/src/lib/eval/eval_context.h index 6b28e2b161..e1721baf19 100644 --- a/src/lib/eval/eval_context.h +++ b/src/lib/eval/eval_context.h @@ -81,6 +81,11 @@ public: /// cases when the EvalParser is not able to handle the packet. void error(const std::string& what); + /// @brief Fatal error handler + /// + /// This is for should not happen but fatal errors + static void fatal(const std::string& what); + private: /// @brief Flag determining scanner debugging. bool trace_scanning_; diff --git a/src/lib/eval/lexer.ll b/src/lib/eval/lexer.ll index 71d5eaab03..c534084d6c 100644 --- a/src/lib/eval/lexer.ll +++ b/src/lib/eval/lexer.ll @@ -31,6 +31,9 @@ // The location of the current token. The lexer will keep updating it. This // variable will be useful for logging errors. static isc::eval::location loc; + +// To avoid the call to exit... oops! +#define YY_FATAL_ERROR(msg) isc::eval::EvalContext::fatal(msg) %} /* noyywrap disables automatic rewinding for the next file to parse. Since we @@ -144,8 +147,8 @@ EvalContext::scanStringBegin() YY_BUFFER_STATE buffer; buffer = yy_scan_bytes(string_.c_str(), string_.size()); if (!buffer) { - error("cannot scan string"); - // error throws an exception so this can't be reached + fatal("cannot scan string"); + // fatal() throws an exception so this can't be reached } } @@ -154,3 +157,10 @@ EvalContext::scanStringEnd() { yy_delete_buffer(YY_CURRENT_BUFFER); } + +namespace { +/// To avoid unused function error +class Dummy { + void dummy() { yy_fatal_error("Fix me: how to disable its definition?"); } +}; +}