From dcd9cc4f62138ef94c6c496fc214045f44e62d4d Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Thu, 30 May 2024 22:20:36 -0400 Subject: Fix crash in AnalysisMergeConflict::GetPathItem --- collaboration.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'collaboration.cpp') diff --git a/collaboration.cpp b/collaboration.cpp index 7b0057c3..b4f7d659 100644 --- a/collaboration.cpp +++ b/collaboration.cpp @@ -2101,15 +2101,65 @@ Ref AnalysisMergeConflict::GetSecondSnapshot() } -std::any AnalysisMergeConflict::GetPathItem(const std::string& path) +template <> +std::any AnalysisMergeConflict::GetPathItem(const std::string& path) { void* val = BNAnalysisMergeConflictGetPathItem(m_object, path.c_str()); if (val == nullptr) - return {}; + throw SyncException(fmt::format("Failed to find merge conflict path item \"{}\"", path)); return *(std::any*)val; } +template <> +uint64_t AnalysisMergeConflict::GetPathItem(const std::string& path) +{ + std::any anyVal = GetPathItem(path); + try + { + return std::any_cast(anyVal); + } + catch (const std::exception& e) + { + throw SyncException(fmt::format( + "Failed to cast merge conflict path item \"{}\" from \"{}\" to \"{}\": {}", + path, anyVal.type().name(), typeid(uint64_t).name(), e.what() + )); + } +} + + +template <> +std::string AnalysisMergeConflict::GetPathItem(const std::string& path) +{ + char* val = BNAnalysisMergeConflictGetPathItemString(m_object, path.c_str()); + if (val == nullptr) + throw SyncException(fmt::format("Failed to find merge conflict path item \"{}\"", path)); + + std::string strVal = val; + BNFreeString(val); + return strVal; +} + + +template <> +nlohmann::json AnalysisMergeConflict::GetPathItem(const std::string& path) +{ + std::any anyVal = GetPathItem(path); + try + { + return std::any_cast(anyVal); + } + catch (const std::exception& e) + { + throw SyncException(fmt::format( + "Failed to cast merge conflict path item \"{}\" from \"{}\" to \"{}\": {}", + path, anyVal.type().name(), typeid(nlohmann::json).name(), e.what() + )); + } +} + + bool AnalysisMergeConflict::Success(std::nullopt_t value) { return BNAnalysisMergeConflictSuccess(m_object, nullptr); -- cgit v1.3.1