Hook up warning for an incomplete scanlist in scanf format strings.

llvm-svn: 108542
This commit is contained in:
Ted Kremenek 2010-07-16 18:28:03 +00:00
parent c618728e8d
commit d7b31cc60d
4 changed files with 12 additions and 3 deletions

View File

@ -2985,7 +2985,7 @@ def warn_printf_ignored_flag: Warning<
"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

View File

@ -41,7 +41,7 @@ static bool ParseScanList(FormatStringHandler &H,
// 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 @@ static bool ParseScanList(FormatStringHandler &H,
// 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;
}
}

View File

@ -1617,9 +1617,17 @@ public:
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,

View File

@ -11,4 +11,5 @@ void test(const char *s, int *i) {
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}}
}