aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-05-13 16:06:05 +0000
committerTed Kremenek <kremenek@apple.com>2009-05-13 16:06:05 +0000
commit42ae3e81a811362c0bf78deb71b72455aadff772 (patch)
tree6a8bf1a238b7bada88d38f42b7c1dda99f5b920e /lib/Sema/SemaChecking.cpp
parent2033a95c9b2692441ce0de790f0d8bbe01722c7f (diff)
Fix <rdar://problem/6880975> [format string] Assertion failed: (Arg < NumArgs && "Arg access out of range!").
For format string checking, only check the type of the format specifier for non-vararg functions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71672 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 67d9a1acbf..22dcc49b55 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -917,36 +917,38 @@ void Sema::CheckPrintfString(const StringLiteral *FExpr,
case '*': {
++numConversions;
- if (!HasVAListArg && numConversions > numDataArgs) {
+ if (!HasVAListArg) {
+ if (numConversions > numDataArgs) {
+ SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);
+
+ if (Str[StrIdx-1] == '.')
+ Diag(Loc, diag::warn_printf_asterisk_precision_missing_arg)
+ << OrigFormatExpr->getSourceRange();
+ else
+ Diag(Loc, diag::warn_printf_asterisk_width_missing_arg)
+ << OrigFormatExpr->getSourceRange();
+
+ // Don't do any more checking. We'll just emit spurious errors.
+ return;
+ }
+
+ // Perform type checking on width/precision specifier.
+ const Expr *E = TheCall->getArg(format_idx+numConversions);
+ if (const BuiltinType *BT = E->getType()->getAsBuiltinType())
+ if (BT->getKind() == BuiltinType::Int)
+ break;
+
SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);
-
+
if (Str[StrIdx-1] == '.')
- Diag(Loc, diag::warn_printf_asterisk_precision_missing_arg)
- << OrigFormatExpr->getSourceRange();
+ Diag(Loc, diag::warn_printf_asterisk_precision_wrong_type)
+ << E->getType() << E->getSourceRange();
else
- Diag(Loc, diag::warn_printf_asterisk_width_missing_arg)
- << OrigFormatExpr->getSourceRange();
+ Diag(Loc, diag::warn_printf_asterisk_width_wrong_type)
+ << E->getType() << E->getSourceRange();
- // Don't do any more checking. We'll just emit spurious errors.
- return;
+ break;
}
-
- // Perform type checking on width/precision specifier.
- const Expr *E = TheCall->getArg(format_idx+numConversions);
- if (const BuiltinType *BT = E->getType()->getAsBuiltinType())
- if (BT->getKind() == BuiltinType::Int)
- break;
-
- SourceLocation Loc = getLocationOfStringLiteralByte(FExpr, StrIdx);
-
- if (Str[StrIdx-1] == '.')
- Diag(Loc, diag::warn_printf_asterisk_precision_wrong_type)
- << E->getType() << E->getSourceRange();
- else
- Diag(Loc, diag::warn_printf_asterisk_width_wrong_type)
- << E->getType() << E->getSourceRange();
-
- break;
}
// Characters which can terminate a format conversion