зеркало из https://github.com/microsoft/clang-1.git
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:
Родитель
e14654b3b7
Коммит
4dcb18ff9d
|
@ -46,6 +46,8 @@ public:
|
|||
PercentArg, // '%'
|
||||
// Objective-C specific specifiers.
|
||||
ObjCObjArg, // '@'
|
||||
// GlibC specific specifiers.
|
||||
PrintErrno, // 'm'
|
||||
// Specifier ranges.
|
||||
IntArgBeg = dArg,
|
||||
IntArgEnd = iArg,
|
||||
|
@ -69,6 +71,16 @@ public:
|
|||
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 isIntArg() const { return kind >= dArg && kind <= iArg; }
|
||||
bool isUIntArg() const { return kind >= oArg && kind <= XArg; }
|
||||
|
|
|
@ -192,6 +192,12 @@ static FormatSpecifierResult ParseFormatSpecifier(FormatStringHandler &H,
|
|||
return true;
|
||||
}
|
||||
|
||||
if (*I == '\0') {
|
||||
// Detect spurious null characters, which are likely errors.
|
||||
H.HandleNullChar(I);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Finally, look for the conversion specifier.
|
||||
const char *conversionPosition = I++;
|
||||
ConversionSpecifier::Kind k = ConversionSpecifier::InvalidSpecifier;
|
||||
|
@ -220,6 +226,8 @@ static FormatSpecifierResult ParseFormatSpecifier(FormatStringHandler &H,
|
|||
case '%': k = ConversionSpecifier::PercentArg; break;
|
||||
// Objective-C.
|
||||
case '@': k = ConversionSpecifier::ObjCObjArg; break;
|
||||
// Glibc specific.
|
||||
case 'm': k = ConversionSpecifier::PrintErrno; break;
|
||||
}
|
||||
FS.setConversionSpecifier(ConversionSpecifier(conversionPosition, k));
|
||||
|
||||
|
@ -246,7 +254,7 @@ bool clang::ParseFormatString(FormatStringHandler &H,
|
|||
// We have a format specifier. Pass it to the callback.
|
||||
if (!H.HandleFormatSpecifier(FSR.getValue(), FSR.getStart(),
|
||||
I - FSR.getStart()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
assert(I == E && "Format string not exhausted");
|
||||
return false;
|
||||
|
|
Загрузка…
Ссылка в новой задаче