From 9b69f523a7f34cf59eacda99f3678649b1eca52c Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Sun, 10 Oct 1993 08:56:49 -0400 Subject: [PATCH] (check_format_info): Support X/Open formats like "%1$d". From-SVN: r5707 --- gcc/c-common.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/gcc/c-common.c b/gcc/c-common.c index 19fa2669ffb..b6bc0e47f79 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -528,10 +528,12 @@ check_format_info (info, params) tree cur_param; tree cur_type; tree wanted_type; + tree first_fillin_param; char *format_chars; format_char_info *fci; static char message[132]; char flag_chars[8]; + int has_operand_number = 0; /* Skip to format argument. If the argument isn't available, there's no work for us to do; prototype checking will catch the problem. */ @@ -577,13 +579,15 @@ check_format_info (info, params) params = TREE_CHAIN (params); ++arg_num; } + + first_fillin_param = params; while (1) { if (*format_chars == 0) { if (format_chars - TREE_STRING_POINTER (format_tree) != format_length) warning ("embedded `\\0' in format"); - if (info->first_arg_num != 0 && params != 0) + if (info->first_arg_num != 0 && params != 0 && ! has_operand_number) warning ("too many arguments for format"); return; } @@ -611,6 +615,34 @@ check_format_info (info, params) } else { + /* See if we have a number followed by a dollar sign. If we do, + it is an operand number, so set PARAMS to that operand. */ + if (*format_chars >= '0' && *format_chars <= '9') + { + char *p = format_chars; + + while (*p >= '0' && *p++ <= '9') + ; + + if (*p == '$') + { + int opnum = atoi (format_chars); + + params = first_fillin_param; + format_chars = p + 1; + has_operand_number = 1; + + for (i = 1; i < opnum && params != 0; i++) + params = TREE_CHAIN (params); + + if (opnum == 0 || params == 0) + { + warning ("operand number out of range in format"); + return; + } + } + } + while (*format_chars != 0 && index (" +#0-", *format_chars) != 0) { if (index (flag_chars, *format_chars) != 0)