]> granicus.if.org Git - clang/commitdiff
fix format specifier fixit for printf("%ld", "foo");
authorHans Wennborg <hans@hanshq.net>
Fri, 9 Dec 2011 10:51:29 +0000 (10:51 +0000)
committerHans Wennborg <hans@hanshq.net>
Fri, 9 Dec 2011 10:51:29 +0000 (10:51 +0000)
It should reset the length modifier (unless it's a wchar_t string).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146252 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/PrintfFormatString.cpp
test/Sema/format-strings-fixit.c

index e14c95229258b15ea6308b4f811ea70afbc67b81..097cc62a6c0dda536c5d0ff28fcc1eb0392acbab 100644 (file)
@@ -366,6 +366,8 @@ bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt) {
     // Set the long length modifier for wide characters
     if (QT->getPointeeType()->isWideCharType())
       LM.setKind(LengthModifier::AsWideChar);
+    else
+      LM.setKind(LengthModifier::None);
 
     return true;
   }
index e87d8acef5696b86f9a91d0aa0d7e5620ab3db03..bfb54327b7582254fcab7d835c1d32abf5035f9a 100644 (file)
@@ -42,7 +42,7 @@ void test() {
   // Bad length modifiers
   printf("%hhs", "foo");
   printf("%1$zp", (void *)0);
-  
+
   // Perserve the original formatting for unsigned integers.
   unsigned long val = 42;
   printf("%X", val);
@@ -57,6 +57,9 @@ void test() {
   printf("%f", (intmax_t) 42);
   printf("%f", (uintmax_t) 42);
   printf("%f", (ptrdiff_t) 42);
+
+  // string
+  printf("%ld", "foo");
 }
 
 // Validate the fixes...
@@ -83,3 +86,4 @@ void test() {
 // CHECK: printf("%jd", (intmax_t) 42);
 // CHECK: printf("%ju", (uintmax_t) 42);
 // CHECK: printf("%td", (ptrdiff_t) 42);
+// CHECK: printf("%s", "foo");