From cd6de9cd34351b12b09480d2f6fc8cdd4248862b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Thu, 2 Mar 2017 18:18:28 +0100 Subject: [PATCH] Don't reconstruct expression on encountering fatal error In some cases, like when given ```cpp std::vector* str = reinterpret_cast*>(0x1234458); CHECK(*str == std::vector()); ``` reconstructing the expression to report it would cause another fatal error. Instead we just put together an AssertionResult without reconstructing the expression fully. This should fully fix #810 --- include/internal/catch_fatal_condition.hpp | 1 - include/internal/catch_run_context.hpp | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/internal/catch_fatal_condition.hpp b/include/internal/catch_fatal_condition.hpp index 5dd10eae..1d6674fc 100644 --- a/include/internal/catch_fatal_condition.hpp +++ b/include/internal/catch_fatal_condition.hpp @@ -53,7 +53,6 @@ namespace Catch { static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) { - reset(); reportFatal(signalDefs[i].name); } } diff --git a/include/internal/catch_run_context.hpp b/include/internal/catch_run_context.hpp index ff63ee2a..496c32cd 100644 --- a/include/internal/catch_run_context.hpp +++ b/include/internal/catch_run_context.hpp @@ -224,10 +224,14 @@ namespace Catch { } virtual void handleFatalErrorCondition( std::string const& message ) { - ResultBuilder resultBuilder = makeUnexpectedResultBuilder(); - resultBuilder.setResultType( ResultWas::FatalErrorCondition ); - resultBuilder << message; - resultBuilder.captureExpression(); + // Don't rebuild the result -- the stringification itself can cause more fatal errors + // Instead, fake a result data. + AssertionResultData tempResult; + tempResult.resultType = ResultWas::FatalErrorCondition; + tempResult.message = message; + AssertionResult result(m_lastAssertionInfo, tempResult); + + getResultCapture().assertionEnded(result); handleUnfinishedSections();