From f0fd9dd1aed105b7a5bd0609df3ef1ce5f8f846c Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 7 Dec 2008 06:28:26 +0100 Subject: [PATCH] fix a potential segfault in the Lumiera exception base class --- src/common/error.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/common/error.cpp b/src/common/error.cpp index f26fd3f16..90e2e6f6d 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -41,12 +41,19 @@ namespace lumiera { * catch clauses. * @todo to be localised */ - inline const string default_usermsg (Error* exception_obj) throw() + inline const string + default_usermsg (Error* exception_obj) throw() { return string("Sorry, Lumiera encountered an internal error. (") + typeid(*exception_obj).name() + ")"; } + inline const char* + default_or_given (const char* id) + { + return id? id : LUMIERA_ERROR_STATE; + } + /* constants to be used as error IDs */ LUMIERA_ERROR_DEFINE (LOGIC , "internal logic broken"); @@ -67,7 +74,7 @@ namespace lumiera { /** @note we set the C-style errorstate as a side effect */ Error::Error (string description, const char* id) throw() : std::exception (), - id_ (id), + id_ (default_or_given (id)), msg_ (error::default_usermsg (this)), desc_ (description), cause_ ("") @@ -79,7 +86,7 @@ namespace lumiera { Error::Error (std::exception& cause, string description, const char* id) throw() : std::exception (), - id_ (id), + id_ (default_or_given (id)), msg_ (error::default_usermsg (this)), desc_ (description), cause_ (extractCauseMsg(cause))