diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -1066,6 +1066,9 @@ return llvm::None; unsigned NewIndex = *IndexOptional; + if (NewIndex >= TheCall->getNumArgs()) + return llvm::None; + const Expr *ObjArg = TheCall->getArg(NewIndex); uint64_t Result; if (!ObjArg->tryEvaluateObjectSize(Result, getASTContext(), BOSType)) diff --git a/clang/test/Sema/format-strings-scanf.c b/clang/test/Sema/format-strings-scanf.c --- a/clang/test/Sema/format-strings-scanf.c +++ b/clang/test/Sema/format-strings-scanf.c @@ -69,6 +69,11 @@ scanf("%#.2Lf", ld); // expected-warning{{invalid conversion specifier '#'}} } +void missing_argument_with_length_modifier() { + char buf[30]; + scanf("%s:%900s", buf); // expected-warning{{more '%' conversions than data arguments}} +} + // Test that the scanf call site is where the warning is attached. If the // format string is somewhere else, point to it in a note. void pr9751(void) {