aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/PrintfFormatString.cpp
AgeCommit message (Collapse)Author
2010-07-20Rename 'UnicodeStrArg' to 'SArg'.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108901 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Rename 'ConsumedSoFarArg' -> 'nArg' and 'OutIntPtrArg' to 'nArg' (scanf and ↵Ted Kremenek
printf checking). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108900 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Rename 'VoidPtrArg' to 'pArg' in printf/scanf checking.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108899 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Rename 'CStrArg' to 'sArg' for printf checking to match with the analagous ↵Ted Kremenek
enum for scanf checking. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108898 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-20Rename analyze_printf::ConversionSpecifier::IntAsCharArg to 'cArg' to matchTed Kremenek
analagous enum in analyze_scanf. This is prep for refactoring the logic for handling ConversionSpecifiers for both scanf and printf. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108897 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-16Add most of the boilerplate support for scanf format string checking. This ↵Ted Kremenek
includes handling the parsing of scanf format strings and hooking the checking into Sema. Most of this checking logic piggybacks on what was already there for checking printf format strings, but the checking logic has been refactored to support both. What is left to be done is to support argument type checking in format strings and of course fix the usual tail of bugs that will follow. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108500 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-22Type Type::isRealFloatingType() that vectors are not floating-pointDouglas Gregor
types, updating callers of both isFloatingType() and isRealFloatingType() accordingly. Caught at least one issue where we allowed one to declare a vector of vectors (!), along with cleaning up the standard-conversion logic for C++. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106595 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-18Printf format strings: Added some more tests and fixed some minor bugs.Tom Care
- Precision toStrings shouldn't print a dot when they have no value. - Length of char length modifier is now returned correctly. - Added several fixit tests. Note: fixit tests are currently broken due to a bug in HighlightRange. Marking as XFAIL for now. M test/Sema/format-strings-fixit.c M include/clang/Analysis/Analyses/PrintfFormatString.h M lib/Analysis/PrintfFormatString.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106275 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-17Bug 7394 - Fixed toString representation of Precisions in format strings.Tom Care
M include/clang/Analysis/Analyses/PrintfFormatString.h M lib/Analysis/PrintfFormatString.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106245 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-17Bug 7377: Fixed several bad printf format string bugs.Tom Care
- Added warning for undefined behavior when using field specifier - Added warning for undefined behavior when using length modifier - Fixed warnings for invalid flags - Added warning for ignored flags - Added fixits for the above warnings - Fixed accuracy of detecting several undefined behavior conditions - Receive normal warnings in addition to security warnings when using %n - Fix bug where '+' flag would remain on unsigned conversion suggestions Summary of changes: - Added expanded tests - Added/expanded warnings - Added position info to OptionalAmounts for fixits - Extracted optional flags to a wrapper class with position info for fixits - Added several methods to validate a FormatSpecifier by component, each checking for undefined behavior - Fixed conversion specifier checking to conform to C99 standard - Added hooks to detect the invalid states in CheckPrintfHandler::HandleFormatSpecifier Note: warnings involving the ' ' (space) flag are temporarily disabled until whitespace highlighting no longer triggers assertions. I will make a post about this on cfe-dev shortly. M test/Sema/format-strings.c M include/clang/Basic/DiagnosticSemaKinds.td M include/clang/Analysis/Analyses/PrintfFormatString.h M lib/Analysis/PrintfFormatString.cpp M lib/Sema/SemaChecking.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106233 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-16Extend format string type-checking to include '%p'. Fixes remaining cases ↵Ted Kremenek
PR 4468. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106151 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-11Small fixes regarding printf fix suggestions.Tom Care
- Added some handling of flags that become invalid when changing the conversion specifier. - Changed fixit behavior to remove unnecessary length modifiers. - Separated some tests out and added some comments. modified: lib/Analysis/PrintfFormatString.cpp test/Sema/format-strings-fixit.c git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105807 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-09Fix a typo that breaks the GCC build. Turns out that Clang isn'tDouglas Gregor
diagnosing this code as an error when it should, so I've filed http://llvm.org/bugs/show_bug.cgi?id=7325. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105683 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-09Added FixIt support to printf format string checking.Tom Care
- Refactored LengthModifier to be a class. - Added toString methods in all member classes of FormatSpecifier. - FixIt suggestions keep user specified flags unless incorrect. Limitations: - The suggestions are not conversion specifier sensitive. For example, if we have a 'pad with zeroes' flag, and the correction is a string conversion specifier, we do not remove the flag. Clang will warn us on the next compilation. A test/Sema/format-strings-fixit.c M include/clang/Analysis/Analyses/PrintfFormatString.h M lib/Analysis/PrintfFormatString.cpp M lib/Sema/SemaChecking.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@105680 91177308-0d34-0410-b5e6-96231b3b80d8
2010-03-25Fix '+=' accumulation error when parsing numeric amounts in a format string.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99479 91177308-0d34-0410-b5e6-96231b3b80d8
2010-03-01Allow a '0' precision in format strings (as the man page says it is okay).Ted Kremenek
Fixes <rdar://problem/7700339>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97482 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-27For printf format string checking, add support for positional format strings.Ted Kremenek
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
2010-02-26For printf format string checking, move the tracking of the data argument ↵Ted Kremenek
index out of Sema and into analyze_printf::ParseFormatString(). Also use a bitvector to determine what arguments have been covered (instead of just checking to see if the last argument consumed is the max argument). This is prep. for support positional arguments (an IEEE extension). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97248 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-24Add support for '%C' and '%S' printf conversion specifiers.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97005 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-16Refactor the logic for printf argument type-checking into ↵Ted Kremenek
analyze_printf::ArgTypeResult. Implement printf argument type checking for '%s'. Fixes <rdar://problem/3065808>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96310 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-09Convert tabs to spaces.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95621 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-04Move ParseFormatString() and FormatStringHandler back into the ↵Ted Kremenek
analyze_printf namespace. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95324 91177308-0d34-0410-b5e6-96231b3b80d8
2010-02-01Add format string type checking support for 'long double'.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95026 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-30Recognize 'q' as a format length modifier (from BSD).Daniel Dunbar
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94894 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-30Add format string checking of 'double' arguments. Fixes ↵Ted Kremenek
<rdar://problem/6931734>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94867 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Fix spacing.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94852 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Per a suggestion from Cristian Draghici, add a method to FormatSpecifier ↵Ted Kremenek
that returns the expected type of the matching data argument. It isn't complete, but should handle several of the important cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94851 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Enhancements to the alternate (WIP) format string checking:Ted Kremenek
- 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
2010-01-29Alternate format string checking: issue warnings for incomplete format ↵Ted Kremenek
specifiers. In addition, move ParseFormatString() and FormatStringHandler() from the clang::analyze_printf to the clang namespace. Hopefully this will resolve some link errors on Linux. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94794 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Alternate format string checking: issue a warning for invalid conversion ↵Ted Kremenek
specifiers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94792 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Yet another attempt to make the Linux buildbots happy. Apparently there are ↵Ted Kremenek
differences on how nested namespaces are handled... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94790 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Move definition of FormatStringHandler::~FormatStringHandler() within ↵Ted Kremenek
namespace directives. Hopefully this will make the Linux buildbots happy. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94784 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-29Add precision/field width checking to AlternateCheckPrintfString().Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94774 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Fix off-by-one error in ParseFormatSpecifier() when reporting the location ↵Ted Kremenek
of a null character. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94762 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Add position of conversion specifier character to 'ConversionSpecifier'.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94739 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Rename namespace clang::printf to clang::analyze_printf to avoid problems ↵Ted Kremenek
where the reference to 'printf' is ambiguous. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94733 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Allow HandleFormatSpecifier() to indicate that no more processing of the ↵Ted Kremenek
format string is desired. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94715 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Add '@' conversion specifier.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94713 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Remove invalid conversion specifiers from format string checking.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94707 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-28Add a few more conversion specifiers to ParseFormatSpecifier (these appear ↵Ted Kremenek
in SemaChecking). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94704 91177308-0d34-0410-b5e6-96231b3b80d8
2010-01-27Add skeleton for a more structured way to analyzing pring formatTed Kremenek
strings than what we currently have in Sema. This is both an experiment and a WIP. The idea is simple: parse the format string incrementally, constructing a well-structure representation of each format specifier. Each format specifier is then handed back one-by-one to a client via a callback. Malformed format strings are also handled with callbacks. The idea is to separate the parsing of the format string from the emission of diagnostics. Currently what we have in Sema for handling format strings is a mongrel of both that is hard to follow and difficult to modify (I can apply this label since I'm the original author of that code). This is in libAnalysis as it is reasonable generic and can potentially be used both by libSema and libChecker. Comments welcome. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94702 91177308-0d34-0410-b5e6-96231b3b80d8