Commit 677ff441 by Jim Wilson

(decl_attributes...

(decl_attributes, format case): Error if num_arg does
not point to a string type argument, or if first_arg_num not the
anonymous argument.

From-SVN: r4032
parent 1b8297c1
...@@ -275,6 +275,8 @@ decl_attributes (decl, attributes) ...@@ -275,6 +275,8 @@ decl_attributes (decl, attributes)
int format_num = TREE_INT_CST_LOW (TREE_PURPOSE (TREE_VALUE (list))); int format_num = TREE_INT_CST_LOW (TREE_PURPOSE (TREE_VALUE (list)));
int first_arg_num = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (list))); int first_arg_num = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (list)));
int is_scan; int is_scan;
tree argument;
int arg_num;
if (TREE_CODE (decl) != FUNCTION_DECL) if (TREE_CODE (decl) != FUNCTION_DECL)
{ {
...@@ -299,6 +301,34 @@ decl_attributes (decl, attributes) ...@@ -299,6 +301,34 @@ decl_attributes (decl, attributes)
"format string arg follows the args to be formatted, for `%s'"); "format string arg follows the args to be formatted, for `%s'");
return; return;
} }
/* Verify that the format_num argument is actually a string, in case
the format attribute is in error. */
argument = TYPE_ARG_TYPES (TREE_TYPE (decl));
for (arg_num = 1; ; ++arg_num)
{
if (argument == 0 || arg_num == format_num)
break;
argument = TREE_CHAIN (argument);
}
if (! argument
|| TREE_CODE (TREE_VALUE (argument)) != POINTER_TYPE
|| (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_VALUE (argument)))
!= char_type_node))
{
error_with_decl (decl,
"format string arg not a string type, for `%s'");
return;
}
/* Verify that first_arg_num points to the last argument, the ... */
while (argument)
arg_num++, argument = TREE_CHAIN (argument);
if (arg_num != first_arg_num)
{
error_with_decl (decl,
"args to be formatted is not ..., for `%s'");
return;
}
record_format_info (DECL_NAME (decl), is_scan, format_num, record_format_info (DECL_NAME (decl), is_scan, format_num,
first_arg_num); first_arg_num);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment