diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2002-05-03 21:17:57 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2002-05-03 21:17:57 +0100 |
commit | 5a3085c52322177de6a1896d9c5388898b9daa54 (patch) | |
tree | 26076b1ab9508d93bec2ead731ea7f5f933b8074 /gcc | |
parent | 0659e0e3df6a29122914540ea13e7373ec84ab8e (diff) | |
download | gcc-5a3085c52322177de6a1896d9c5388898b9daa54.zip gcc-5a3085c52322177de6a1896d9c5388898b9daa54.tar.gz gcc-5a3085c52322177de6a1896d9c5388898b9daa54.tar.bz2 |
re PR c/6547 (misleading printf '$' format)
* c-format.c (check_format_info_main): Don't check for presence of
parameter for * width until after operand number has been read,
and only check for it if format parameters are available.
Fixes PR c/6547.
testsuite:
* gcc.dg/format/xopen-2.c: New test.
From-SVN: r53118
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/c-format.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/format/xopen-2.c | 21 |
4 files changed, 37 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b8366ca..33029bb 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2002-05-03 Joseph S. Myers <jsm28@cam.ac.uk> + + * c-format.c (check_format_info_main): Don't check for presence of + parameter for * width until after operand number has been read, + and only check for it if format parameters are available. + Fixes PR c/6547. + 2002-05-03 Jason Thorpe <thorpej@wasabisystems.com> * config/alpha/netbsd.h (CPP_PREDEFINES): Add -D_LP64. diff --git a/gcc/c-format.c b/gcc/c-format.c index e5be439..470ccf7 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -1751,11 +1751,6 @@ check_format_info_main (status, res, info, format_chars, format_length, /* "...a field width...may be indicated by an asterisk. In this case, an int argument supplies the field width..." */ ++format_chars; - if (params == 0) - { - status_warning (status, "too few arguments for format"); - return; - } if (has_operand_number != 0) { int opnum; @@ -1775,6 +1770,11 @@ check_format_info_main (status, res, info, format_chars, format_length, } if (info->first_arg_num != 0) { + if (params == 0) + { + status_warning (status, "too few arguments for format"); + return; + } cur_param = TREE_VALUE (params); if (has_operand_number <= 0) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1a533f3..7ef8018 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-05-03 Joseph S. Myers <jsm28@cam.ac.uk> + + * gcc.dg/format/xopen-2.c: New test. + 2002-05-03 Jakub Jelinek <jakub@redhat.com> * gcc.dg/20020503-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/format/xopen-2.c b/gcc/testsuite/gcc.dg/format/xopen-2.c new file mode 100644 index 0000000..5b83731 --- /dev/null +++ b/gcc/testsuite/gcc.dg/format/xopen-2.c @@ -0,0 +1,21 @@ +/* Test for X/Open format extensions, as found in the + Single Unix Specification. Test for bug reported by + Pierre-Canalsat PETIT <pierrecanalsat.petit.canalsat@canal-plus.com> + in PR c/6547. The test for absence of a parameter for a * width was done + too early in the case of operand numbers and vprintf formats. +*/ +/* Origin: Joseph Myers <jsm28@cam.ac.uk> */ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99 -Wformat" } */ + +#include "format.h" + +void vbar (va_list, const char *) __attribute__((__format__(__printf__, 2, 0))); + +void +foo (int i, int j, va_list va) +{ + printf("%2$*1$c", i, j); + printf("%2$*1$c %2$*1$c", i, j); /* { dg-bogus "too few" "bogus too few dollar" } */ + vbar(va, "%*s"); /* { dg-bogus "too few" "bogus too few vprintf" } */ +} |