r207573 - scanf analysis: handle scanlists that start with ^] (PR19559)

Hans Wennborg hans at hanshq.net
Tue Apr 29 12:42:27 PDT 2014


Author: hans
Date: Tue Apr 29 14:42:27 2014
New Revision: 207573

URL: http://llvm.org/viewvc/llvm-project?rev=207573&view=rev
Log:
scanf analysis: handle scanlists that start with ^] (PR19559)

Modified:
    cfe/trunk/lib/Analysis/ScanfFormatString.cpp
    cfe/trunk/test/Sema/format-strings-scanf.c

Modified: cfe/trunk/lib/Analysis/ScanfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ScanfFormatString.cpp?rev=207573&r1=207572&r2=207573&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ScanfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/ScanfFormatString.cpp Tue Apr 29 14:42:27 2014
@@ -50,6 +50,15 @@ static bool ParseScanList(FormatStringHa
     }
   }
 
+  // Special case: "]^" are the first characters.
+  if (I + 1 != E && I[0] == '^' && I[1] == ']') {
+    I += 2;
+    if (I == E) {
+      H.HandleIncompleteScanList(start, I - 1);
+      return true;
+    }
+  }
+
   // Look for a ']' character which denotes the end of the scan list.
   while (*I != ']') {
     if (++I == E) {

Modified: cfe/trunk/test/Sema/format-strings-scanf.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings-scanf.c?rev=207573&r1=207572&r2=207573&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-scanf.c (original)
+++ cfe/trunk/test/Sema/format-strings-scanf.c Tue Apr 29 14:42:27 2014
@@ -86,6 +86,11 @@ void test_scanlist(int *ip, char *sp, wc
   scanf("%h[abc]", sp); // expected-warning{{length modifier 'h' results in undefined behavior or no effect with '[' conversion specifier}}
   scanf("%l[xyx]", ls); // no-warning
   scanf("%ll[xyx]", ls); // expected-warning {{length modifier 'll' results in undefined behavior or no effect with '[' conversion specifier}}
+
+  // PR19559
+  scanf("%[]% ]", sp); // no-warning
+  scanf("%[^]% ]", sp); // no-warning
+  scanf("%[a^]% ]", sp); // expected-warning {{invalid conversion specifier ' '}}
 }
 
 void test_alloc_extension(char **sp, wchar_t **lsp, float *fp) {





More information about the cfe-commits mailing list