Add builtin definition for scanf, including extending the builtin encoding to

represent builtins that have the "scanf" attribution (via the format attribute) just
like we do with printf functions.  Follow-up work is needed to add similar support
for fscanf et al.

This is to support format-string checking for scanf functions.

llvm-svn: 108499
This commit is contained in:
Ted Kremenek
2010-07-16 02:11:15 +00:00
parent 103c4ebea5
commit 5932c35138
4 changed files with 37 additions and 0 deletions

View File

@@ -93,3 +93,23 @@ Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx,
return true;
}
// FIXME: Refactor with isPrintfLike.
bool
Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx,
bool &HasVAListArg) {
const char *Scanf = strpbrk(GetRecord(ID).Attributes, "sS");
if (!Scanf)
return false;
HasVAListArg = (*Scanf == 'S');
++Scanf;
assert(*Scanf == ':' && "s or S specifier must have be followed by a ':'");
++Scanf;
assert(strchr(Scanf, ':') && "printf specifier must end with a ':'");
FormatIdx = strtol(Scanf, 0, 10);
return true;
}