aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/format-strings.c
AgeCommit message (Collapse)Author
2013-01-12Add a comment to test to clarify the intention hereDmitri Gribenko
Comment is taken from the commit message of r151080, by Jean-Daniel Dupas git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172332 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-08Format strings: suggest %lld instead of %qd and %Ld with -Wformat-non-iso.Jordan Rose
As a corollary to the previous commit, even when an extension is available, we can still offer a fixit to the standard modifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163453 91177308-0d34-0410-b5e6-96231b3b80d8
2012-09-08Format strings: %Ld isn't available on Darwin or Windows.Jordan Rose
This seems to be a GNU libc extension; we offer a fixit to %lld on these platforms. <rdar://problem/11518237> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163452 91177308-0d34-0410-b5e6-96231b3b80d8
2012-08-07Properly check length modfiers for %n in format strings.Hans Wennborg
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161408 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-31-Wformat: better handling of qualifiers on pointer argumentsHans Wennborg
Warn about using pointers to const-qualified types as arguments to scanf. Ignore the volatile qualifier when checking if types match. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161052 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-30Do not warn on correct use of the '%n' format specifier.Matt Beaumont-Gay
While '%n' can be used for evil in an attacker-controlled format string, there isn't any acute danger in using it in a literal format string with an argument of the appropriate type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160984 91177308-0d34-0410-b5e6-96231b3b80d8
2012-07-30Make -Wformat check the argument type for %n.Hans Wennborg
This makes Clang check that the corresponding argument for "%n" in a format string is a pointer to int. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160966 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-17Use the argument location instead of the format string location when warningMatt Beaumont-Gay
about argument type mismatch. This gives a nicer diagnostic in cases like printf(fmt, i); where previously the snippet just pointed at 'fmt' (with a note at the definition of fmt). It's a wash for cases like printf("%f", i); where previously we snippeted the offending portion of the format string, but didn't indicate which argument was at fault. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156968 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-11Merge branch 'format-string-braced-init'Matt Beaumont-Gay
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156653 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-11Fix a recent regression with the merging of format attributes.Rafael Espindola
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156597 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-08Make -Wformat accept printf("%hhx", c); with -funsigned-charHans Wennborg
For "%hhx", printf expects an unsigned char. This makes Clang accept a 'char' argument for that also when using -funsigned-char. This fixes PR12761. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156388 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-04Add a predefine __WINT_UNSIGNED__, similar to __WCHAR_UNSIGNED__, and test ↵James Molloy
them both for ARM and X86. Use this to fully fix Sema/format-strings.c for non-x86 platforms. Reviewed by Chandler on IRC. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156169 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-04Fix handling of wint_t - we can't assume wint_t is purely an integer ↵James Molloy
promotion of wchar_t - they may differ in signedness. Teach ASTContext about WIntType, and have it taken from TargetInfo like WCharType. Should fix test/Sema/format-strings.c for ARM, with the exception of one subtest which will fail if wint_t and wchar_t are the same size and wint_t is signed, wchar_t is unsigned. There'll be a followup commit to fix that. Reviewed by Chandler and Hans at http://llvm.org/reviews/r/8 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156165 91177308-0d34-0410-b5e6-96231b3b80d8
2012-05-03Add a test for r156092.Bob Wilson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156132 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-22Warn about non-standard format strings (pr12017)Hans Wennborg
This adds the -Wformat-non-standard flag (off by default, enabled by -pedantic), which warns about non-standard things in format strings (such as the 'q' length modifier, the 'S' conversion specifier, etc.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151154 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-21When calling a non variadic format function(vprintf, vscanf, NSLogv, …), ↵Jean-Daniel Dupas
warn if the format string argument is a parameter that is not itself declared as a format string with compatible format. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151080 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-16Format string analysis: give 'q' its own enumerator.Hans Wennborg
This is in preparation for being able to warn about 'q' and other non-standard format string features. It also allows us to print its name correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150697 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-13Fix typo in PrintfConversionSpecifier::isDoubleArg()Hans Wennborg
This makes the printf diagnostics issue warnigns for %a, %A, %e, etc. when used with the wrong argument. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150370 91177308-0d34-0410-b5e6-96231b3b80d8
2012-02-07non-literal strftime format string is not unsafe.Jean-Daniel Dupas
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150009 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-31FormatCheckers should emit all diagnostics using EmitFormatDiagnostic().Jean-Daniel Dupas
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149394 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-30Update on format attribute handling.Jean-Daniel Dupas
- Remove the printf0 special handling as we treat it as printf anyway. - Perform basic checks (non-literal, empty) for all formats and not only printf/scanf. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149236 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-24Teach scanf/printf checking about '%Ld' and friends (a GNU extension). ↵Ted Kremenek
Fixes PR 9466. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148859 91177308-0d34-0410-b5e6-96231b3b80d8
2012-01-20Tighten format string diagnostic and make it a bit clearer (and a bit closer ↵Ted Kremenek
to GCC's). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148579 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-28Fix for PR9751 to change the behavior of -Wformat warnings. If the formatRichard Trieu
string is part of the function call, then there is no difference. If the format string is not, the warning will point to the call site and a note will point to where the format string is. Fix-it hints for strings are moved to the note if a note is emitted. This will prevent changes to format strings that may be used in multiple places. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143168 91177308-0d34-0410-b5e6-96231b3b80d8
2011-10-25Tweak printf format string parsing to accept 'hh' conversion specifier to ↵Ted Kremenek
accept any char, not just signed char. Fixes <rdar://problem/10303638>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142908 91177308-0d34-0410-b5e6-96231b3b80d8
2011-09-29Do not warn about empty format strings when there are no data arguments. ↵Ted Kremenek
Fixes <rdar://problem/9473155>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140777 91177308-0d34-0410-b5e6-96231b3b80d8
2011-08-27Control 'invalid conversion specifier' warnings under a subflag ↵Ted Kremenek
(-Wformat-invalid-specifier) of -Wformat. Fixes <rdar://problem/10031930>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138686 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-14Revert r135147 and r135075. The consensus was that this wasn't the right ↵Ted Kremenek
thing to do. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135152 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-14Reapply r135075, but modify format-strings.c and format-strings-fixit.c test ↵Ted Kremenek
cases to be more portable with an explicit target triple. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135134 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-13Re-relax conversion specifier checking for printf format strings and ↵Ted Kremenek
conversion specifiers. My recent change was a mistake. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135048 91177308-0d34-0410-b5e6-96231b3b80d8
2011-07-13Fix inversion in argument type checking for format strings with conversion ↵Ted Kremenek
specifiers for character types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135046 91177308-0d34-0410-b5e6-96231b3b80d8
2011-06-15Don't add redundant FormatAttr, ConstAttr, or NoThrowAttr attributes,Douglas Gregor
either imlicitly (for builtins) or explicitly (due to multiple specification of the same attributes). Fixes <rdar://problem/9612060>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133045 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-24Don't warn about using PredefinedExprs as format string literals. These ↵Ted Kremenek
never can be a real security issue. Fixes PR 9314. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126447 91177308-0d34-0410-b5e6-96231b3b80d8
2011-02-21Allow -Wformat to be enabled without -Wformat-security. GCC gatesChandler Carruth
-Wformat-security on -Wformat, not vice-versa. Fixes PR8486. Patch by Oleg Slezberg. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126096 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08Add semantic checking that the "thousands grouping"Ted Kremenek
prefix in a printf format string is matched with the appropriate conversion specifier. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123055 91177308-0d34-0410-b5e6-96231b3b80d8
2011-01-08Add printf format string parsing support for 'Ted Kremenek
prefix to format conversions (POSIX extension). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123054 91177308-0d34-0410-b5e6-96231b3b80d8
2010-12-02Fix range in printf warnings for invalid conversion specifiers.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120735 91177308-0d34-0410-b5e6-96231b3b80d8
2010-11-21The 'X' printf type has a valid alternative form. Fixes PR8641.Anders Carlsson
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119946 91177308-0d34-0410-b5e6-96231b3b80d8
2010-10-21Previously, the printf warnings would say your arguments type was 'int' when ↵Ted Kremenek
it was really a 'char' or a 'short'. This fixes that and allows the hints to suggest 'h' modifiers for small ints. Patch by Justin Bogner! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116996 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-09Check format strings when a called function has more than one FormatAttr ↵Ted Kremenek
(one for 'scanf' and one for 'printf'). Fixes <rdar://problem/8409437>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113472 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-09It appears that technically a null format string is not warned under ↵Ted Kremenek
-Wformat-nonliteral, as the function processing the format string can decided whether or not to accept a null format string (e.g., asl_log). Fixes <rdar://problem/8269537>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113469 91177308-0d34-0410-b5e6-96231b3b80d8
2010-08-24Fix printf format string checking for '%lc' (which expects a wint_t or ↵Ted Kremenek
compatible argument). Fixes PR 7981. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111978 91177308-0d34-0410-b5e6-96231b3b80d8
2010-07-19Don't warn when a '%%' or '%*d' (scanf) is used in a format string with ↵Ted Kremenek
positional arguments, since these don't actually consume an argument. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108757 91177308-0d34-0410-b5e6-96231b3b80d8
2010-06-21Bug 7377: printf checking fails to flag some undefined behavior Tom Care
http://llvm.org/bugs/show_bug.cgi?id=7377 Updated format string highlighting and fixits to take advantage of the new CharSourceRange class. - Change HighlightRange to allow highlighting whitespace only in a CharSourceRange (for warnings about the ' ' (space) flag) - Change format specifier range helper function to allow for half-open ranges (+1 to end) - Enabled previously failing tests (FIXMEs/XFAILs removed) - Small fixes and additions to format string test cases M test/Sema/format-strings.c M test/Sema/format-strings-fixit.c M lib/Frontend/TextDiagnosticPrinter.cpp M lib/Sema/SemaChecking.cpp git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106480 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-17Fix format string checking of '%c' by treating it as an integer conversion. ↵Ted Kremenek
Fixes PR 7391. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106196 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-05-26Tell the string literal parser when it's not permitted to emitDouglas Gregor
diagnostics. That would be while we're parsing string literals for the sole purpose of producing a diagnostic about them. Fixes <rdar://problem/8026030>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104684 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-22Whenever we complain about a failed initialization of a function orDouglas Gregor
method parameter, provide a note pointing at the parameter itself so the user does not have to manually look for the function/method being called and match up parameters to arguments. For example, we now get: t.c:4:5: warning: incompatible pointer types passing 'long *' to parameter of type 'int *' [-pedantic] f(long_ptr); ^~~~~~~~ t.c:1:13: note: passing argument to parameter 'x' here void f(int *x); ^ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102038 91177308-0d34-0410-b5e6-96231b3b80d8
2010-03-25Fix two bugs in format-string checking:Ted Kremenek
(1) Do not assume the data arguments start after the format string (2) Do not use the fact that a function is variadic to treat it like a va_list printf function Fixes PR 6697. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99480 91177308-0d34-0410-b5e6-96231b3b80d8