[cfe-commits] r109427 - /cfe/trunk/lib/Sema/SemaChecking.cpp
Ted Kremenek
kremenek at apple.com
Mon Jul 26 12:45:42 PDT 2010
Author: kremenek
Date: Mon Jul 26 14:45:42 2010
New Revision: 109427
URL: http://llvm.org/viewvc/llvm-project?rev=109427&view=rev
Log:
Consolidate #args checking for scanf/printf format strings.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=109427&r1=109426&r2=109427&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Jul 26 14:45:42 2010
@@ -1169,6 +1169,11 @@
SourceLocation getLocationOfByte(const char *x);
const Expr *getDataArg(unsigned i) const;
+
+ bool CheckNumArgs(const analyze_format_string::FormatSpecifier &FS,
+ const analyze_format_string::ConversionSpecifier &CS,
+ const char *startSpecifier, unsigned specifierLen,
+ unsigned argIndex);
};
}
@@ -1270,6 +1275,30 @@
return keepGoing;
}
+bool
+CheckFormatHandler::CheckNumArgs(
+ const analyze_format_string::FormatSpecifier &FS,
+ const analyze_format_string::ConversionSpecifier &CS,
+ const char *startSpecifier, unsigned specifierLen, unsigned argIndex) {
+
+ if (argIndex >= NumDataArgs) {
+ if (FS.usesPositionalArg()) {
+ S.Diag(getLocationOfByte(CS.getStart()),
+ diag::warn_printf_positional_arg_exceeds_data_args)
+ << (argIndex+1) << NumDataArgs
+ << getSpecifierRange(startSpecifier, specifierLen);
+ }
+ else {
+ S.Diag(getLocationOfByte(CS.getStart()),
+ diag::warn_printf_insufficient_data_args)
+ << getSpecifierRange(startSpecifier, specifierLen);
+ }
+
+ return false;
+ }
+ return true;
+}
+
//===--- CHECK: Printf format string checking ------------------------------===//
namespace {
@@ -1538,22 +1567,8 @@
if (HasVAListArg)
return true;
- if (argIndex >= NumDataArgs) {
- if (FS.usesPositionalArg()) {
- S.Diag(getLocationOfByte(CS.getStart()),
- diag::warn_printf_positional_arg_exceeds_data_args)
- << (argIndex+1) << NumDataArgs
- << getSpecifierRange(startSpecifier, specifierLen);
- }
- else {
- S.Diag(getLocationOfByte(CS.getStart()),
- diag::warn_printf_insufficient_data_args)
- << getSpecifierRange(startSpecifier, specifierLen);
- }
-
- // Don't do any more checking.
+ if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex))
return false;
- }
// Now type check the data expression that matches the
// format specifier.
@@ -1714,22 +1729,8 @@
if (HasVAListArg)
return true;
- if (argIndex >= NumDataArgs) {
- if (FS.usesPositionalArg()) {
- S.Diag(getLocationOfByte(CS.getStart()),
- diag::warn_printf_positional_arg_exceeds_data_args)
- << (argIndex+1) << NumDataArgs
- << getSpecifierRange(startSpecifier, specifierLen);
- }
- else {
- S.Diag(getLocationOfByte(CS.getStart()),
- diag::warn_printf_insufficient_data_args)
- << getSpecifierRange(startSpecifier, specifierLen);
- }
-
- // Don't do any more checking.
+ if (!CheckNumArgs(FS, CS, startSpecifier, specifierLen, argIndex))
return false;
- }
// FIXME: Check that the argument type matches the format specifier.
More information about the cfe-commits
mailing list