Enhancements to the alternate (WIP) format string checking:

- Add ConversionSpecifier::consumesDataArgument() as a helper method
  to determine if a conversion specifier requires a matching argument.
- Add support for glibc-specific '%m' conversion
- Add an extra callback to HandleNull() for locations within the
  format specifier that have a null character


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94834 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ted Kremenek 2010-01-29 20:29:53 +00:00
Родитель e14654b3b7
Коммит 4dcb18ff9d
2 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -46,6 +46,8 @@ public:
PercentArg, // '%' PercentArg, // '%'
// Objective-C specific specifiers. // Objective-C specific specifiers.
ObjCObjArg, // '@' ObjCObjArg, // '@'
// GlibC specific specifiers.
PrintErrno, // 'm'
// Specifier ranges. // Specifier ranges.
IntArgBeg = dArg, IntArgBeg = dArg,
IntArgEnd = iArg, IntArgEnd = iArg,
@ -68,6 +70,16 @@ public:
const char *getStart() const { const char *getStart() const {
return Position; return Position;
} }
bool consumesDataArgument() const {
switch (kind) {
case PercentArg:
case PrintErrno:
return false;
default:
return true;
}
}
bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; } bool isObjCArg() const { return kind >= ObjCBeg && kind <= ObjCEnd; }
bool isIntArg() const { return kind >= dArg && kind <= iArg; } bool isIntArg() const { return kind >= dArg && kind <= iArg; }

Просмотреть файл

@ -191,6 +191,12 @@ static FormatSpecifierResult ParseFormatSpecifier(FormatStringHandler &H,
H.HandleIncompleteFormatSpecifier(Start, E - Start); H.HandleIncompleteFormatSpecifier(Start, E - Start);
return true; return true;
} }
if (*I == '\0') {
// Detect spurious null characters, which are likely errors.
H.HandleNullChar(I);
return true;
}
// Finally, look for the conversion specifier. // Finally, look for the conversion specifier.
const char *conversionPosition = I++; const char *conversionPosition = I++;
@ -219,7 +225,9 @@ static FormatSpecifierResult ParseFormatSpecifier(FormatStringHandler &H,
case 'n': k = ConversionSpecifier::OutIntPtrArg; break; case 'n': k = ConversionSpecifier::OutIntPtrArg; break;
case '%': k = ConversionSpecifier::PercentArg; break; case '%': k = ConversionSpecifier::PercentArg; break;
// Objective-C. // Objective-C.
case '@': k = ConversionSpecifier::ObjCObjArg; break; case '@': k = ConversionSpecifier::ObjCObjArg; break;
// Glibc specific.
case 'm': k = ConversionSpecifier::PrintErrno; break;
} }
FS.setConversionSpecifier(ConversionSpecifier(conversionPosition, k)); FS.setConversionSpecifier(ConversionSpecifier(conversionPosition, k));
@ -246,7 +254,7 @@ bool clang::ParseFormatString(FormatStringHandler &H,
// We have a format specifier. Pass it to the callback. // We have a format specifier. Pass it to the callback.
if (!H.HandleFormatSpecifier(FSR.getValue(), FSR.getStart(), if (!H.HandleFormatSpecifier(FSR.getValue(), FSR.getStart(),
I - FSR.getStart())) I - FSR.getStart()))
return false; return true;
} }
assert(I == E && "Format string not exhausted"); assert(I == E && "Format string not exhausted");
return false; return false;