diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-05-15 00:44:02 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-05-15 00:44:02 +0000 |
commit | 448748a4ffb8191534a16145b3b1e90f131ab208 (patch) | |
tree | 5a17c82d4a869e1134d2e5c2dbe9cf8ab06adb7d /gcc/c-format.c | |
parent | de91b75fc50d73b6a589827d145a535e8db97c1d (diff) | |
download | gcc-448748a4ffb8191534a16145b3b1e90f131ab208.tar.gz |
PR c/15444
* c-format.c (avoid_dollar_number): New function.
(check_format_info_main): Call avoid_dollar_number when operand
numbers might occur but has_operand_number == 0.
testsuite:
* gcc.dg/format/xopen-1.c: Adjust expected message.
* gcc.dg/format/xopen-3.c: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@81871 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-format.c')
-rw-r--r-- | gcc/c-format.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/gcc/c-format.c b/gcc/c-format.c index 17ef68a608a..c4a6ecedb9b 100644 --- a/gcc/c-format.c +++ b/gcc/c-format.c @@ -1023,6 +1023,7 @@ static void status_warning (int *, const char *, ...) static void init_dollar_format_checking (int, tree); static int maybe_read_dollar_number (int *, const char **, int, tree, tree *, const format_kind_info *); +static bool avoid_dollar_number (int *, const char *); static void finish_dollar_format_checking (int *, format_check_results *, int); static const format_flag_spec *get_flag_spec (const format_flag_spec *, @@ -1304,6 +1305,26 @@ maybe_read_dollar_number (int *status, const char **format, return argnum; } +/* Ensure that FORMAT does not start with a decimal number followed by + a $; give a diagnostic and return true if it does, false otherwise. */ + +static bool +avoid_dollar_number (int *status, const char *format) +{ + if (!ISDIGIT (*format)) + return false; + while (ISDIGIT (*format)) + format++; + if (*format == '$') + { + status_warning (status, + "$ operand number used after format" + " without operand number"); + return true; + } + return false; +} + /* Finish the checking for a format string that used $ operand number formats instead of non-$ formats. We check for unused operands before used ones @@ -1721,6 +1742,11 @@ check_format_info_main (int *status, format_check_results *res, main_arg_num = opnum + info->first_arg_num - 1; } } + else if (fki->flags & FMT_FLAG_USE_DOLLAR) + { + if (avoid_dollar_number (status, format_chars)) + return; + } /* Read any format flags, but do not yet validate them beyond removing duplicates, since in general validation depends on the rest of @@ -1780,6 +1806,11 @@ check_format_info_main (int *status, format_check_results *res, else has_operand_number = 0; } + else + { + if (avoid_dollar_number (status, format_chars)) + return; + } if (info->first_arg_num != 0) { if (params == 0) @@ -1879,6 +1910,11 @@ check_format_info_main (int *status, format_check_results *res, else has_operand_number = 0; } + else + { + if (avoid_dollar_number (status, format_chars)) + return; + } if (info->first_arg_num != 0) { if (params == 0) |