diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-02-27 01:41:03 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-02-27 01:41:03 +0000 |
commit | efaff195ba1fa55b6fe0b0b2435b81451387d241 (patch) | |
tree | 1923cd17053f841ed7e5035ace8f32637df29049 /include/clang/Analysis/Analyses/PrintfFormatString.h | |
parent | c8dfe5ece04e683106eb96c58a2999f70b53ac21 (diff) |
For printf format string checking, add support for positional format strings.
Along the way, coelesce some of the diagnostics.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97297 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Analysis/Analyses/PrintfFormatString.h')
-rw-r--r-- | include/clang/Analysis/Analyses/PrintfFormatString.h | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/include/clang/Analysis/Analyses/PrintfFormatString.h b/include/clang/Analysis/Analyses/PrintfFormatString.h index f66892f185..18c92743cf 100644 --- a/include/clang/Analysis/Analyses/PrintfFormatString.h +++ b/include/clang/Analysis/Analyses/PrintfFormatString.h @@ -150,13 +150,17 @@ enum LengthModifier { class OptionalAmount { public: - enum HowSpecified { NotSpecified, Constant, Arg }; + enum HowSpecified { NotSpecified, Constant, Arg, Invalid }; OptionalAmount(HowSpecified h, unsigned i, const char *st) : start(st), hs(h), amt(i) {} - OptionalAmount() - : start(0), hs(NotSpecified), amt(0) {} + OptionalAmount(bool b = true) + : start(0), hs(b ? NotSpecified : Invalid), amt(0) {} + + bool isInvalid() const { + return hs == Invalid; + } HowSpecified getHowSpecified() const { return hs; } @@ -191,6 +195,7 @@ class FormatSpecifier { unsigned HasSpacePrefix : 1; unsigned HasAlternativeForm : 1; unsigned HasLeadingZeroes : 1; + unsigned UsesPositionalArg : 1; unsigned argIndex; ConversionSpecifier CS; OptionalAmount FieldWidth; @@ -198,7 +203,8 @@ class FormatSpecifier { public: FormatSpecifier() : LM(None), IsLeftJustified(0), HasPlusPrefix(0), HasSpacePrefix(0), - HasAlternativeForm(0), HasLeadingZeroes(0), argIndex(0) {} + HasAlternativeForm(0), HasLeadingZeroes(0), UsesPositionalArg(0), + argIndex(0) {} static FormatSpecifier Parse(const char *beg, const char *end); @@ -214,6 +220,7 @@ public: void setHasSpacePrefix() { HasSpacePrefix = 1; } void setHasAlternativeForm() { HasAlternativeForm = 1; } void setHasLeadingZeros() { HasLeadingZeroes = 1; } + void setUsesPositionalArg() { UsesPositionalArg = 1; } void setArgIndex(unsigned i) { assert(CS.consumesDataArgument()); @@ -263,8 +270,11 @@ public: bool hasAlternativeForm() const { return (bool) HasAlternativeForm; } bool hasLeadingZeros() const { return (bool) HasLeadingZeroes; } bool hasSpacePrefix() const { return (bool) HasSpacePrefix; } + bool usesPositionalArg() const { return (bool) UsesPositionalArg; } }; +enum PositionContext { FieldWidthPos = 0, PrecisionPos = 1 }; + class FormatStringHandler { public: FormatStringHandler() {} @@ -275,6 +285,11 @@ public: virtual void HandleNullChar(const char *nullCharacter) {} + virtual void HandleInvalidPosition(const char *startPos, unsigned posLen, + PositionContext p) {} + + virtual void HandleZeroPosition(const char *startPos, unsigned posLen) {} + virtual bool HandleInvalidConversionSpecifier(const analyze_printf::FormatSpecifier &FS, const char *startSpecifier, |