Skip to content

Commit

Permalink
Fix crash that can occur when failure pointers are null (microsoft#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcPMS authored Jan 28, 2022
1 parent 4bead76 commit 2491b6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/AppInstallerCommonCore/AppInstallerTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
}
}

0 comments on commit 2491b6b

Please sign in to comment.