commit 2491b6bb29054aa829221fbb0838cc03e18c7e95 parent 4bead76bc8d97db85df0e93a67a028fb22624ecf Author: JohnMcPMS <johnmcp@microsoft.com> Date: Thu, 27 Jan 2022 16:14:44 -0800 Fix crash that can occur when failure pointers are null (#1880) Diffstat:
| M | src/AppInstallerCommonCore/AppInstallerTelemetry.cpp | | | 4 | ++-- |
| M | src/AppInstallerCommonCore/Public/AppInstallerStrings.h | | | 13 | +++++++++++++ |
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp @@ -219,10 +219,10 @@ namespace AppInstaller::Logging m_summary.FailureHResult = failure.hr; m_summary.FailureMessage = anonMessage; - m_summary.FailureModule = failure.pszModule; + m_summary.FailureModule = StringOrEmptyIfNull(failure.pszModule); m_summary.FailureThreadId = failure.threadId; m_summary.FailureType = ConvertWilFailureTypeToFailureType(failure.type); - m_summary.FailureFile = failure.pszFile; + m_summary.FailureFile = StringOrEmptyIfNull(failure.pszFile); m_summary.FailureLine = failure.uLineNumber; } diff --git a/src/AppInstallerCommonCore/Public/AppInstallerStrings.h b/src/AppInstallerCommonCore/Public/AppInstallerStrings.h @@ -177,4 +177,17 @@ namespace AppInstaller::Utility { return ConvertContainerToString(container, [](const auto& item) { return item; }); } + + template <typename CharType> + std::basic_string<CharType> StringOrEmptyIfNull(const CharType* string) + { + if (string) + { + return { string }; + } + else + { + return {}; + } + } }