From 457928217ef7c2ea36aa20346df4e0790044ae35 Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 7 Nov 2025 16:43:22 -0500 Subject: Fix crash when attempting to open an invalid file. --- transformcontext.cpp | 10 ++++++++-- transformsession.cpp | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/transformcontext.cpp b/transformcontext.cpp index 9b01e306..92514296 100644 --- a/transformcontext.cpp +++ b/transformcontext.cpp @@ -17,7 +17,10 @@ TransformContext::~TransformContext() Ref TransformContext::GetInput() const { - return new BinaryView(BNTransformContextGetInput(m_object)); + BNBinaryView* view = BNTransformContextGetInput(m_object); + if (!view) + return nullptr; + return new BinaryView(view); } @@ -123,7 +126,10 @@ void TransformContext::SetTransformResult(BNTransformResult result) Ref TransformContext::GetMetadata() const { - return new Metadata(BNTransformContextGetMetadata(m_object)); + BNMetadata* metadata = BNTransformContextGetMetadata(m_object); + if (!metadata) + return nullptr; + return new Metadata(metadata); } diff --git a/transformsession.cpp b/transformsession.cpp index 9cf5cf3b..14aabcea 100644 --- a/transformsession.cpp +++ b/transformsession.cpp @@ -41,19 +41,28 @@ TransformSession::~TransformSession() Ref TransformSession::GetCurrentView() const { - return new BinaryView(BNTransformSessionGetCurrentView(m_object)); + BNBinaryView* view = BNTransformSessionGetCurrentView(m_object); + if (!view) + return nullptr; + return new BinaryView(view); } Ref TransformSession::GetRootContext() const { - return new TransformContext(BNTransformSessionGetRootContext(m_object)); + BNTransformContext* context = BNTransformSessionGetRootContext(m_object); + if (!context) + return nullptr; + return new TransformContext(context); } Ref TransformSession::GetCurrentContext() const { - return new TransformContext(BNTransformSessionGetCurrentContext(m_object)); + BNTransformContext* context = BNTransformSessionGetCurrentContext(m_object); + if (!context) + return nullptr; + return new TransformContext(context); } -- cgit v1.3.1