Commit Graph

38 Commits

Author SHA1 Message Date
Alexander Shaposhnikov 593e4bbf4e [clang] Fix handling of "%zd" in scanf
This diff addresses FIXMEs in lib/Analysis/ScanfFormatString.cpp 
for the case of ssize_t format specifier and adds tests.
In particular, this change enables Clang to emit a warning 
on incorrect using of "%zd"/"%zn".

Test plan: make check-all

Differential revision: https://reviews.llvm.org/D35652

llvm-svn: 308662
2017-07-20 20:11:47 +00:00
Bruno Cardoso Lopes dc195d005f [Sema] Attempt to fix tests for utf-8 invalid format string specifiers
Followup from r264752.

Attempt to appease buildbots:
 http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/2882
 http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/2619

llvm-svn: 264765
2016-03-29 18:38:44 +00:00
Bruno Cardoso Lopes 0c18d03d91 [Sema] Handle UTF-8 invalid format string specifiers
Improve invalid format string specifier handling by printing out
invalid specifiers characters with \x, \u and \U. Previously clang
would print gargabe whenever the character is unprintable.

Example, before:
  NSLog(@"%\u25B9"); => warning: invalid conversion specifier ' [-Wformat-invalid-specifier]
after:
  NSLog(@"%\u25B9"); => warning: invalid conversion specifier '\u25b9' [-Wformat-invalid-specifier]

Differential Revision: http://reviews.llvm.org/D18296

rdar://problem/24672159

llvm-svn: 264752
2016-03-29 17:35:02 +00:00
Andy Gibbs 9a31b3b07a Reduce false positives in printf/scanf format checker
Summary:
The printf/scanf format checker is a little over-zealous in handling the conditional operator.  This patch reduces work by not checking code-paths that are never used and reduces false positives regarding uncovered arguments, for example in the code fragment:

printf(minimal ? "%i\n" : "%i: %s\n", code, msg);

Reviewers: rtrieu

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D15636

llvm-svn: 262025
2016-02-26 15:35:16 +00:00
Hans Wennborg df51ee6c50 scanf analysis: handle scanlists that start with ^] (PR19559)
llvm-svn: 207573
2014-04-29 19:42:27 +00:00
Alp Toker 6ed7251683 Revert "Don't require -re suffix on -verify directives with regexes."
This patch was submitted to the list for review and didn't receive a LGTM.

(In fact one explicit objection and one query were raised.)

This reverts commit r197295.

llvm-svn: 197299
2013-12-14 01:07:05 +00:00
Hans Wennborg 9b395ef284 Don't require -re suffix on -verify directives with regexes.
Differential Revision: http://llvm-reviews.chandlerc.com/D2392

llvm-svn: 197295
2013-12-14 00:46:53 +00:00
Hans Wennborg cda4b6dd00 Change semantics of regex expectations in the diagnostic verifier
Previously, a line like

  // expected-error-re {{foo}}

treats the entirety of foo as a regex. This is inconvenient when matching type
names containing regex characters. For example, to match
"void *(class test8::A::*)(void)" inside such a regex, one would have to type
"void \*\(class test8::A::\*\)\(void\)".

This patch changes the semantics of expected-error-re to only treat the parts
of the directive wrapped in double curly braces as regexes. This avoids the
escaping problem and leads to nicer patterns for those cases; see e.g. the
change to test/Sema/format-strings-scanf.c.

(The balanced search for closing }} of a directive also makes us handle the
full directive in test\SemaCXX\constexpr-printing.cpp:41 and :53.)

Differential Revision: http://llvm-reviews.chandlerc.com/D2388

llvm-svn: 197092
2013-12-11 23:40:50 +00:00
NAKAMURA Takumi e06bc926bb clang/test/Sema/format-strings-scanf.c: Relax a couple of expressions with expected-warning-re to let matched for Win32 targets.
- format specifies type 'wchar_t **' (aka 'int **') but the argument has type 'float *'
- format specifies type 'wchar_t **' (aka 'unsigned short **') but the argument has type 'float *'

llvm-svn: 163468
2012-09-08 12:06:00 +00:00
Jordan Rose 92303592c3 Format strings: %Ld isn't available on Darwin or Windows.
This seems to be a GNU libc extension; we offer a fixit to %lld on
these platforms.

<rdar://problem/11518237>

llvm-svn: 163452
2012-09-08 04:00:03 +00:00
Hans Wennborg abc1e22d65 Properly check length modfiers for %n in format strings.
llvm-svn: 161408
2012-08-07 09:13:19 +00:00
Hans Wennborg b1ab2a84f0 Remove ScanfArgType and bake that logic into ArgType.
This is useful for example for %n in printf, which expects
a pointer to int with the same logic for checking as %d
would have in scanf.

llvm-svn: 161407
2012-08-07 08:59:46 +00:00
Hans Wennborg 16250c7c18 -Wformat: better handling of qualifiers on pointer arguments
Warn about using pointers to const-qualified types as arguments to
scanf. Ignore the volatile qualifier when checking if types match.

llvm-svn: 161052
2012-07-31 16:37:47 +00:00
Hans Wennborg ebcd1c7ca2 Make -Wformat check the argument type for %n.
This makes Clang check that the corresponding argument for "%n" in a
format string is a pointer to int.

llvm-svn: 160966
2012-07-30 17:11:32 +00:00
Hans Wennborg 9bc9bcc247 Format string analysis: give 'q' its own enumerator.
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.

llvm-svn: 150697
2012-02-16 16:34:54 +00:00
Jean-Daniel Dupas cb197b0e42 FormatCheckers should emit all diagnostics using EmitFormatDiagnostic().
llvm-svn: 149394
2012-01-31 18:12:08 +00:00
Ted Kremenek 6fa5727939 Teach scanf/printf checking about '%Ld' and friends (a GNU extension). Fixes PR 9466.
llvm-svn: 148859
2012-01-24 21:29:54 +00:00
Ted Kremenek 9139892728 The 'l' length modifier makes sense with the scanlist conversion specifier.
llvm-svn: 148586
2012-01-20 22:11:52 +00:00
Ted Kremenek e7b9d4342b Tighten format string diagnostic and make it a bit clearer (and a bit closer to GCC's).
llvm-svn: 148579
2012-01-20 21:52:58 +00:00
Hans Wennborg 507b567707 Treat -Wformat=0 as an alias for -Wformat.
Fixes PR9195.

llvm-svn: 148300
2012-01-17 09:30:38 +00:00
Hans Wennborg 6073e31baa scanf: parse the 'm' length modifier, and check that the right arguments
are used with that and the 'a' length modifier.

llvm-svn: 148029
2012-01-12 17:11:12 +00:00
Hans Wennborg fd950878fa scanf analysis: the 'a' length modifier is valid with a scanlist
Before r148025 we (accidentally) didn't check whether a length modifier is
appropriate for a scanlist, but now we do.

llvm-svn: 148026
2012-01-12 15:07:16 +00:00
Hans Wennborg 32f115f9c1 scanf analysis: don't bail out after successful parse of scanlist
llvm-svn: 148025
2012-01-12 14:44:54 +00:00
Hans Wennborg 29b653413a Fix test/Sema/format-strings-scanf.c
llvm-svn: 146651
2011-12-15 11:43:45 +00:00
Hans Wennborg 23926bd2d7 Support the 'a' length modifier in scanf format strings as a C90
extension.

This fixes gcc.dg/format/c90-scanf-3.c and ext-4.c (test for excess
errors).

llvm-svn: 146649
2011-12-15 10:25:47 +00:00
Hans Wennborg 4951c67875 Fix signature of vsscanf in Builtins.def
llvm-svn: 146392
2011-12-12 18:46:05 +00:00
Hans Wennborg 8d5a4093f5 Fix signature of sscanf in Builtins.def
llvm-svn: 146390
2011-12-12 18:33:02 +00:00
Hans Wennborg bb4189db23 Make fscanf, vscanf, etc. be recognized as scanf-like functions.
llvm-svn: 146367
2011-12-12 10:34:18 +00:00
Hans Wennborg b1a5e09f6f Check that arguments to a scanf call match the format specifier,
and offer fixits when there is a mismatch.

llvm-svn: 146326
2011-12-10 13:20:11 +00:00
Richard Trieu 03cf7b70e0 Fix for PR9751 to change the behavior of -Wformat warnings. If the format
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.

llvm-svn: 143168
2011-10-28 00:41:25 +00:00
Ted Kremenek 4407ea4948 Hookup checking for invalid length modifiers in scanf format strings.
llvm-svn: 108907
2010-07-20 20:04:47 +00:00
Ted Kremenek 6cd694233d Don't warn when a '%%' or '%*d' (scanf) is used in a format string with positional arguments, since
these don't actually consume an argument.

llvm-svn: 108757
2010-07-19 22:01:06 +00:00
Ted Kremenek ce81542d61 Hook up 'invalid conversion' warning for scanf format strings.
llvm-svn: 108750
2010-07-19 21:25:57 +00:00
Ted Kremenek 5c3e1b9a54 Add missing conversion specifier parsing for 'u', 'x', 'o', and 's'. Fixes <rdar://problem/8204052>.
llvm-svn: 108742
2010-07-19 19:47:40 +00:00
Ted Kremenek 0030be81f5 Remove unicode quotes characters that somehow made it into a recent commit of mine.
llvm-svn: 108552
2010-07-16 20:49:01 +00:00
Ted Kremenek d7b31cc60d Hook up warning for an incomplete scanlist in scanf format strings.
llvm-svn: 108542
2010-07-16 18:28:03 +00:00
Ted Kremenek c618728e8d Tweak zero-field width in scanf format string diagnostic.
llvm-svn: 108541
2010-07-16 18:27:56 +00:00
Ted Kremenek 5530131bb7 Add initial test cases for scanf format string checking.
llvm-svn: 108503
2010-07-16 02:11:34 +00:00