[cfe-commits] r108542 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Analysis/ScanfFormatString.cpp lib/Sema/SemaChecking.cpp test/Sema/format-strings-scanf.c
Ted Kremenek
kremenek at apple.com
Fri Jul 16 11:28:03 PDT 2010
Author: kremenek
Date: Fri Jul 16 13:28:03 2010
New Revision: 108542
URL: http://llvm.org/viewvc/llvm-project?rev=108542&view=rev
Log:
Hook up warning for an incomplete scanlist in scanf format strings.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Analysis/ScanfFormatString.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/format-strings-scanf.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=108542&r1=108541&r2=108542&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 16 13:28:03 2010
@@ -2985,7 +2985,7 @@
"flag '%0' is ignored when flag '%1' is present">,
InGroup<Format>;
def warn_scanf_scanlist_incomplete : Warning<
- "scanlist not terminated in format string">,
+ "no closing â]â for â%%[â in scanf format string">,
InGroup<Format>;
// CHECK: returning address/reference of stack memory
Modified: cfe/trunk/lib/Analysis/ScanfFormatString.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ScanfFormatString.cpp?rev=108542&r1=108541&r2=108542&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/ScanfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/ScanfFormatString.cpp Fri Jul 16 13:28:03 2010
@@ -41,7 +41,7 @@
// Special case: ']' is the first character.
if (*I == ']') {
if (++I == E) {
- H.HandleIncompleteScanList(start, I);
+ H.HandleIncompleteScanList(start, I - 1);
return true;
}
}
@@ -49,7 +49,7 @@
// Look for a ']' character which denotes the end of the scan list.
while (*I != ']') {
if (++I == E) {
- H.HandleIncompleteScanList(start, I);
+ H.HandleIncompleteScanList(start, I - 1);
return true;
}
}
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=108542&r1=108541&r2=108542&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Jul 16 13:28:03 2010
@@ -1617,9 +1617,17 @@
bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
const char *startSpecifier,
unsigned specifierLen);
+
+ void HandleIncompleteScanList(const char *start, const char *end);
};
}
+void CheckScanfHandler::HandleIncompleteScanList(const char *start,
+ const char *end) {
+ S.Diag(getLocationOfByte(end), diag::warn_scanf_scanlist_incomplete)
+ << getSpecifierRange(start, end - start);
+}
+
bool CheckScanfHandler::HandleScanfSpecifier(
const analyze_scanf::ScanfSpecifier &FS,
const char *startSpecifier,
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=108542&r1=108541&r2=108542&view=diff
==============================================================================
--- cfe/trunk/test/Sema/format-strings-scanf.c (original)
+++ cfe/trunk/test/Sema/format-strings-scanf.c Fri Jul 16 13:28:03 2010
@@ -11,4 +11,5 @@
scanf(s, i); // expected-warning{{ormat string is not a string literal}}
scanf("%0d", i); // expected-warning{{zero field width in scanf format string is unused}}
scanf("%00d", i); // expected-warning{{zero field width in scanf format string is unused}}
+ scanf("%d%[asdfasdfd", i, s); // expected-warning{{no closing â]â for â%[â in scanf format string}}
}
More information about the cfe-commits
mailing list