Skip to content

Commit 1c0e722

Browse files
authored
[Clang] Prevent null pointer dereference in DiagnoseDeclAvailability() (#97095)
This patch adds an assertion in the DiagnoseDeclAvailabilit() function to ensure that the expected availability attribute is not null before they are passed to hasMatchingEnvironmentOrNone() to prevent potential null pointer dereferences and improve the robustness of the availability diagnostics process.
1 parent a5e905b commit 1c0e722

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

clang/lib/Sema/SemaAvailability.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ void DiagnoseUnguardedAvailability::DiagnoseDeclAvailability(
842842

843843
const AvailabilityAttr *AA =
844844
getAttrForPlatform(SemaRef.getASTContext(), OffendingDecl);
845+
assert(AA != nullptr && "expecting valid availability attribute");
845846
bool EnvironmentMatchesOrNone =
846847
hasMatchingEnvironmentOrNone(SemaRef.getASTContext(), AA);
847848
VersionTuple Introduced = AA->getIntroduced();

0 commit comments

Comments
 (0)