[cfe-commits] r94834 - in /cfe/trunk: include/clang/Analysis/Analyses/PrintfFormatString.h lib/Analysis/PrintfFormatString.cpp

Ted Kremenek kremenek at apple.com
Fri Jan 29 12:29:54 PST 2010


Author: kremenek
Date: Fri Jan 29 14:29:53 2010
New Revision: 94834

URL: http://llvm.org/viewvc/llvm-project?rev=94834&view=rev
Log:
Enhancements to the alternate (WIP) format string checking:

- Add ConversionSpecifier::consumesDataArgument() as a helper method
  to determine if a conversion specifier requires a matching argument.
- Add support for glibc-specific '%m' conversion
- Add an extra callback to HandleNull() for locations within the
  format specifier that have a null character

Modified:
    cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h
    cfe/trunk/lib/Analysis/PrintfFormatString.cpp

Modified: cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h?rev=94834&r1=94833&r2=94834&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/PrintfFormatString.h Fri Jan 29 14:29:53 2010
@@ -46,6 +46,8 @@
    PercentArg,    // '%'
     // Objective-C specific specifiers.
    ObjCObjArg,    // '@'
+    // GlibC specific specifiers.
+   PrintErrno,    // 'm'
     // Specifier ranges.
    IntArgBeg = dArg,
    IntArgEnd = iArg,
@@ -68,6 +70,16 @@
   const char *getStart() const {
     return Position;
   }
+	
+  bool consumesDataArgument() const {
+    switch (kind) {
+  	  case PercentArg:
+	  case PrintErrno:
+		return false;
+	  default:
+		return true;
+	}
+  }
   
   bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; }
   bool isIntArg() const { return kind >= dArg && kind <= iArg; }

Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=94834&r1=94833&r2=94834&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Fri Jan 29 14:29:53 2010
@@ -191,6 +191,12 @@
     H.HandleIncompleteFormatSpecifier(Start, E - Start);
     return true;
   }
+	
+  if (*I == '\0') {
+	// Detect spurious null characters, which are likely errors.
+	H.HandleNullChar(I);
+	return true;
+  }
   
   // Finally, look for the conversion specifier.
   const char *conversionPosition = I++;
@@ -219,7 +225,9 @@
     case 'n': k = ConversionSpecifier::OutIntPtrArg; break;
     case '%': k = ConversionSpecifier::PercentArg;   break;      
     // Objective-C.
-    case '@': k = ConversionSpecifier::ObjCObjArg; break;      
+    case '@': k = ConversionSpecifier::ObjCObjArg; break;
+	// Glibc specific.
+    case 'm': k = ConversionSpecifier::PrintErrno; break;
   }
   FS.setConversionSpecifier(ConversionSpecifier(conversionPosition, k));
 
@@ -246,7 +254,7 @@
     // We have a format specifier.  Pass it to the callback.
     if (!H.HandleFormatSpecifier(FSR.getValue(), FSR.getStart(),
                                  I - FSR.getStart()))
-      return false;
+      return true;
   }  
   assert(I == E && "Format string not exhausted");      
   return false;





More information about the cfe-commits mailing list