forked from OSchip/llvm-project
Hook up warning for an incomplete scanlist in scanf format strings.
llvm-svn: 108542
This commit is contained in:
parent
c618728e8d
commit
d7b31cc60d
|
@ -2985,7 +2985,7 @@ def warn_printf_ignored_flag: Warning<
|
||||||
"flag '%0' is ignored when flag '%1' is present">,
|
"flag '%0' is ignored when flag '%1' is present">,
|
||||||
InGroup<Format>;
|
InGroup<Format>;
|
||||||
def warn_scanf_scanlist_incomplete : Warning<
|
def warn_scanf_scanlist_incomplete : Warning<
|
||||||
"scanlist not terminated in format string">,
|
"no closing ‘]’ for ‘%%[’ in scanf format string">,
|
||||||
InGroup<Format>;
|
InGroup<Format>;
|
||||||
|
|
||||||
// CHECK: returning address/reference of stack memory
|
// CHECK: returning address/reference of stack memory
|
||||||
|
|
|
@ -41,7 +41,7 @@ static bool ParseScanList(FormatStringHandler &H,
|
||||||
// Special case: ']' is the first character.
|
// Special case: ']' is the first character.
|
||||||
if (*I == ']') {
|
if (*I == ']') {
|
||||||
if (++I == E) {
|
if (++I == E) {
|
||||||
H.HandleIncompleteScanList(start, I);
|
H.HandleIncompleteScanList(start, I - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ static bool ParseScanList(FormatStringHandler &H,
|
||||||
// Look for a ']' character which denotes the end of the scan list.
|
// Look for a ']' character which denotes the end of the scan list.
|
||||||
while (*I != ']') {
|
while (*I != ']') {
|
||||||
if (++I == E) {
|
if (++I == E) {
|
||||||
H.HandleIncompleteScanList(start, I);
|
H.HandleIncompleteScanList(start, I - 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1617,9 +1617,17 @@ public:
|
||||||
bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
|
bool HandleScanfSpecifier(const analyze_scanf::ScanfSpecifier &FS,
|
||||||
const char *startSpecifier,
|
const char *startSpecifier,
|
||||||
unsigned specifierLen);
|
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(
|
bool CheckScanfHandler::HandleScanfSpecifier(
|
||||||
const analyze_scanf::ScanfSpecifier &FS,
|
const analyze_scanf::ScanfSpecifier &FS,
|
||||||
const char *startSpecifier,
|
const char *startSpecifier,
|
||||||
|
|
|
@ -11,4 +11,5 @@ void test(const char *s, int *i) {
|
||||||
scanf(s, i); // expected-warning{{ormat string is not a string literal}}
|
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("%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("%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}}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue