From 71aca8c86d3721bcbf21f1f1649f07cf732f2090 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 2 Oct 2017 11:41:47 +0100 Subject: Always return a valid pointer in Exception::what() --- libdevcore/Exceptions.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdevcore/Exceptions.cpp') diff --git a/libdevcore/Exceptions.cpp b/libdevcore/Exceptions.cpp index f422d926..25fd1478 100644 --- a/libdevcore/Exceptions.cpp +++ b/libdevcore/Exceptions.cpp @@ -27,7 +27,9 @@ char const* Exception::what() const noexcept if (string const* cmt = comment()) return cmt->c_str(); else - return nullptr; + /// Boost accepts nullptr, but the C++ standard doesn't + /// and crashes on some platforms. + return std::exception::what(); } string Exception::lineInfo() const -- cgit v1.2.3 From 931c0bcce35b05cbe54c0eacb23669e76e1b4a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 2 Oct 2017 16:49:45 +0200 Subject: Refactor Exception::what() --- libdevcore/Exceptions.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libdevcore/Exceptions.cpp') diff --git a/libdevcore/Exceptions.cpp b/libdevcore/Exceptions.cpp index 25fd1478..f204dbc2 100644 --- a/libdevcore/Exceptions.cpp +++ b/libdevcore/Exceptions.cpp @@ -24,12 +24,14 @@ using namespace dev; char const* Exception::what() const noexcept { + // Return the comment if available. if (string const* cmt = comment()) - return cmt->c_str(); - else - /// Boost accepts nullptr, but the C++ standard doesn't - /// and crashes on some platforms. - return std::exception::what(); + return cmt->data(); + + // Fallback to base what(). + // Boost accepts nullptr, but the C++ standard doesn't + // and crashes on some platforms. + return std::exception::what(); } string Exception::lineInfo() const -- cgit v1.2.3