[cfe-commits] r113472 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/format-strings.c

Ted Kremenek kremenek at apple.com
Wed Sep 8 21:33:05 PDT 2010


Author: kremenek
Date: Wed Sep  8 23:33:05 2010
New Revision: 113472

URL: http://llvm.org/viewvc/llvm-project?rev=113472&view=rev
Log:
Check format strings when a called function has more than one FormatAttr (one for 'scanf' and one for 'printf').  Fixes <rdar://problem/8409437>.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/format-strings.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=113472&r1=113471&r2=113472&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Sep  8 23:33:05 2010
@@ -341,8 +341,12 @@
   // more efficient. For example, just map function ids to custom
   // handlers.
 
-  // Printf checking.
-  if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>()) {
+  // Printf and scanf checking.
+  for (specific_attr_iterator<FormatAttr>
+         i = FDecl->specific_attr_begin<FormatAttr>(),
+         e = FDecl->specific_attr_end<FormatAttr>(); i != e ; ++i) {
+
+    const FormatAttr *Format = *i;
     const bool b = Format->getType() == "scanf";
     if (b || CheckablePrintfAttr(Format, TheCall)) {
       bool HasVAListArg = Format->getFirstArg() == 0;
@@ -353,12 +357,11 @@
     }
   }
 
-  specific_attr_iterator<NonNullAttr>
-    i = FDecl->specific_attr_begin<NonNullAttr>(),
-    e = FDecl->specific_attr_end<NonNullAttr>();
-
-  for (; i != e; ++i)
+  for (specific_attr_iterator<NonNullAttr>
+         i = FDecl->specific_attr_begin<NonNullAttr>(),
+         e = FDecl->specific_attr_end<NonNullAttr>(); i != e; ++i) {
     CheckNonNullArguments(*i, TheCall);
+  }
 
   return false;
 }

Modified: cfe/trunk/test/Sema/format-strings.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=113472&r1=113471&r2=113472&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Wed Sep  8 23:33:05 2010
@@ -302,9 +302,18 @@
 }
 
 // <rdar://problem/8269537> -Wformat-security says NULL is not a string literal
-void r8269537() {
+void rdar8269537() {
   // This is likely to crash in most cases, but -Wformat-nonliteral technically
   // doesn't warn in this case.
   printf(0); // no-warning
 }
 
+// Handle functions with multiple format attributes.
+extern void rdar8332221_vprintf_scanf(const char *, va_list, const char *, ...)
+     __attribute__((__format__(__printf__, 1, 0)))
+     __attribute__((__format__(__scanf__, 3, 4)));
+     
+void rdar8332221(va_list ap, int *x, long *y) {
+  rdar8332221_vprintf_scanf("%", ap, "%d", x); // expected-warning{{incomplete format specifier}}
+}
+





More information about the cfe-commits mailing list