public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/6547: misleading printf '$' format
@ 2002-08-23 13:16 jsm28
0 siblings, 0 replies; 5+ messages in thread
From: jsm28 @ 2002-08-23 13:16 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, jsm28, nobody, peio, prpetit
Synopsis: misleading printf '$' format
State-Changed-From-To: open->closed
State-Changed-By: jsm28
State-Changed-When: Fri Aug 23 13:11:50 2002
State-Changed-Why:
Fixed on mainline.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6547
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c/6547: misleading printf '$' format
@ 2002-05-03 13:26 Joseph S. Myers
0 siblings, 0 replies; 5+ messages in thread
From: Joseph S. Myers @ 2002-05-03 13:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/6547; it has been noted by GNATS.
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: Pierre-Canalsat PETIT <pierrecanalsat.petit.canalsat@canal-plus.com>
Cc: <gcc-bugs@gcc.gnu.org>, <gcc-gnats@gcc.gnu.org>,
<gcc-patches@gcc.gnu.org>, <peio@blutch.dyndns.org>,
<prpetit@canal-plus.com>
Subject: Re: c/6547: misleading printf '$' format
Date: Fri, 3 May 2002 21:19:08 +0100 (BST)
On Fri, 3 May 2002, Pierre-Canalsat PETIT wrote:
> int main(int argc, char *argv[]) {
> printf("Usage: %1$s [-n <option 1>] [-m <option 2>]\n"
> " %3$*2$c [-i <input>] [-o <output>] [-c <nb>] [-t <ms>]\n"
> " %3$*2$c <file.in> <file.out>\n", *argv, strlen(*argv), ' ');
> return 0;
> }
>
> This returns me a "warning: too few arguments for format".
> But if you remove the second line of the format, it does compile
> without warning...
Thanks for that bug report. Patch below applied to mainline only
(since it's not a regression). Bootstrapped with no regressions on
i686-pc-linux-gnu.
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.
testsuite:
2002-05-03 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/format/xopen-2.c: New test.
--- c-format.c.orig 2002-04-19 19:10:11.000000000 +0000
+++ c-format.c 2002-05-03 15:01:13.000000000 +0000
@@ -1751,11 +1751,6 @@ check_format_info_main (status, res, inf
/* "...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, inf
}
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)
{
--- testsuite/gcc.dg/format/xopen-2.c 2001-03-26 23:57:02.000000000 +0000
+++ testsuite/gcc.dg/format/xopen-2.c 2002-05-03 14:59:20.000000000 +0000
@@ -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" } */
+}
--
Joseph S. Myers
jsm28@cam.ac.uk
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c/6547: misleading printf '$' format
@ 2002-05-03 7:26 Pierre-Canalsat PETIT
0 siblings, 0 replies; 5+ messages in thread
From: Pierre-Canalsat PETIT @ 2002-05-03 7:26 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/6547; it has been noted by GNATS.
From: "Pierre-Canalsat PETIT" <pierrecanalsat.petit.canalsat@canal-plus.com>
To: jsm28@cam.ac.uk
Cc: gcc-bugs@gcc.gnu.org,
gcc-gnats@gcc.gnu.org,
Joseph Myers <jsm28@srcf.ucam.org>,
peio@blutch.dyndns.org,
prpetit@canal-plus.com
Subject: Re: c/6547: misleading printf '$' format
Date: Fri, 3 May 2002 16:18:13 +0200
> You can't mix $ and non-$ formats in one format string; see the Single
> Unix Specification. Once a non-$ format is detected, $ operand numbers
> are no longer checked for. Note that "%." can only be the start of a
> non-$ format.
====(forgot to answer to all...)====
True.. I forgot that, thanks.
So gcc-3.0 has no misleading warning, good point
(maybe a more verbose warning should be written..).
Note v2.95.4 still has one :
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("%2$.*1$s\n", argc, *argv);
return 0;
}
This gives a "warning: unknown conversion type character '1' in format"
====(Snap)====
There is still a problem it seems on gcc v3.0.4.. :
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
printf("Usage: %1$s [-n <option 1>] [-m <option 2>]\n"
" %3$*2$c [-i <input>] [-o <output>] [-c <nb>] [-t <ms>]\n"
" %3$*2$c <file.in> <file.out>\n", *argv, strlen(*argv), ' ');
return 0;
}
This returns me a "warning: too few arguments for format".
But if you remove the second line of the format, it does compile
without warning...
--
Pierre PETIT
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: c/6547: misleading printf '$' format
@ 2002-05-03 6:56 Joseph S. Myers
0 siblings, 0 replies; 5+ messages in thread
From: Joseph S. Myers @ 2002-05-03 6:56 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/6547; it has been noted by GNATS.
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: <peio@blutch.dyndns.org>
Cc: <gcc-gnats@gcc.gnu.org>, <prpetit@canal-plus.com>,
<gcc-bugs@gcc.gnu.org>
Subject: Re: c/6547: misleading printf '$' format
Date: Fri, 3 May 2002 14:47:23 +0100 (BST)
On 3 May 2002 peio@blutch.dyndns.org wrote:
> With both v2.95 and 3.0, there is a warning on "%.*1$s":
> "warning: unknown conversion type character '1' in format"
> >How-To-Repeat:
> #include <stdio.h>
>
> int main (int argc, char *argv[]) {
> printf("%.*s == %2$.*1$s\n", argc, *argv);
You can't mix $ and non-$ formats in one format string; see the Single
Unix Specification. Once a non-$ format is detected, $ operand numbers
are no longer checked for. Note that "%." can only be the start of a
non-$ format.
--
Joseph S. Myers
jsm28@cam.ac.uk
^ permalink raw reply [flat|nested] 5+ messages in thread
* c/6547: misleading printf '$' format
@ 2002-05-03 6:06 peio
0 siblings, 0 replies; 5+ messages in thread
From: peio @ 2002-05-03 6:06 UTC (permalink / raw)
To: gcc-gnats; +Cc: prpetit
>Number: 6547
>Category: c
>Synopsis: misleading printf '$' format
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri May 03 06:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Pierre PETIT
>Release: gcc version 3.0.4 (and 2.95.4)
>Organization:
>Environment:
Debian GNU/Linux (testing) x86
Linux kernel 2.4.18 - libc v2.2.5
>Description:
Formats with '$' character get a warning on gcc-3.0,
when compiling with -Wall (or at least -Wformat):
"warning: unknown conversion type character '$' in format"
With both v2.95 and 3.0, there is a warning on "%.*1$s":
"warning: unknown conversion type character '1' in format"
>How-To-Repeat:
#include <stdio.h>
int main (int argc, char *argv[]) {
printf("%.*s == %2$.*1$s\n", argc, *argv);
return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-08-23 20:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-23 13:16 c/6547: misleading printf '$' format jsm28
-- strict thread matches above, loose matches on Subject: below --
2002-05-03 13:26 Joseph S. Myers
2002-05-03 7:26 Pierre-Canalsat PETIT
2002-05-03 6:56 Joseph S. Myers
2002-05-03 6:06 peio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).