Skip to content

Commit b63edb6

Browse files
d0kapple-fcloutier
authored andcommitted
[clang] Fix use-after-scope when diagnosting __attribute__((format_matches))
I don't think this will ever crash, but asan complains about it. SUMMARY: AddressSanitizer: stack-use-after-scope clang/lib/Sema/SemaChecking.cpp:6925:43 in void (anonymous namespace)::CheckFormatHandler::EmitFormatDiagnostic<clang::CharSourceRange>(clang::PartialDiagnostic, clang::SourceLocation, bool, clang::CharSourceRange, llvm::ArrayRef<clang::FixItHint>) While there switch to stable_sort to not give a flipped error message half of the time.
1 parent 9d82e5f commit b63edb6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7172,10 +7172,11 @@ bool DecomposePrintfHandler::GetSpecifiers(
71727172
const char *Str = Data.data();
71737173
llvm::SmallBitVector BV;
71747174
UncoveredArgHandler UA;
7175+
const Expr *PrintfArgs[] = {FSL->getFormatString()};
71757176
DecomposePrintfHandler H(S, FSL, FSL->getFormatString(), Type, 0, 0, IsObjC,
7176-
Str, Sema::FAPK_Elsewhere, {FSL->getFormatString()},
7177-
0, InFunctionCall, Sema::VariadicDoesNotApply, BV,
7178-
UA, Args);
7177+
Str, Sema::FAPK_Elsewhere, PrintfArgs, 0,
7178+
InFunctionCall, Sema::VariadicDoesNotApply, BV, UA,
7179+
Args);
71797180

71807181
if (!analyze_format_string::ParsePrintfString(
71817182
H, Str, Str + Data.size(), S.getLangOpts(), S.Context.getTargetInfo(),
@@ -7184,7 +7185,7 @@ bool DecomposePrintfHandler::GetSpecifiers(
71847185
if (H.HadError)
71857186
return false;
71867187

7187-
std::sort(
7188+
std::stable_sort(
71887189
Args.begin(), Args.end(),
71897190
[](const EquatableFormatArgument &A, const EquatableFormatArgument &B) {
71907191
return A.getPosition() < B.getPosition();

0 commit comments

Comments
 (0)