format_check_results *res;
function_format_info *info;
tree params;
- int *status;
} format_check_context;
-static void check_format_info (int *, function_format_info *, tree);
+static void check_format_info (function_format_info *, tree);
static void check_format_arg (void *, tree, unsigned HOST_WIDE_INT);
-static void check_format_info_main (int *, format_check_results *,
+static void check_format_info_main (format_check_results *,
function_format_info *,
const char *, int, tree,
unsigned HOST_WIDE_INT);
-static void status_warning (int *, const char *, ...)
- ATTRIBUTE_GCC_DIAG(2, 3);
static void init_dollar_format_checking (int, tree);
-static int maybe_read_dollar_number (int *, const char **, int,
+static int maybe_read_dollar_number (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 bool avoid_dollar_number (const char *);
+static void finish_dollar_format_checking (format_check_results *, int);
static const format_flag_spec *get_flag_spec (const format_flag_spec *,
int, const char *);
-static void check_format_types (int *, format_wanted_type *);
+static void check_format_types (format_wanted_type *);
/* Decode a format type from a string, returning the type, or
format_type_error if not valid, in which case the caller should print an
attribute themselves. */
void
-check_function_format (int *status, tree attrs, tree params)
+check_function_format (tree attrs, tree params)
{
tree a;
/* Yup; check it. */
function_format_info info;
decode_format_attr (TREE_VALUE (a), &info, 1);
- check_format_info (status, &info, params);
+ check_format_info (&info, params);
if (warn_missing_format_attribute && info.first_arg_num == 0
&& (format_types[info.format_type].flags
& (int) FMT_FLAG_ARG_CONVERT))
}
}
-/* This function replaces `warning' inside the printf format checking
- functions. If the `status' parameter is non-NULL, then it is
- dereferenced and set to 1 whenever a warning is caught. Otherwise
- it warns as usual by replicating the innards of the warning
- function from diagnostic.c. */
-static void
-status_warning (int *status, const char *msgid, ...)
-{
- diagnostic_info diagnostic ;
- va_list ap;
-
- va_start (ap, msgid);
-
- if (status)
- *status = 1;
- else
- {
- /* This duplicates the warning function behavior. */
- diagnostic_set_info (&diagnostic, _(msgid), &ap,
- input_location, DK_WARNING);
- report_diagnostic (&diagnostic);
- }
-
- va_end (ap);
-}
/* Variables used by the checking of $ operand number formats. */
static char *dollar_arguments_used = NULL;
a $ format is found, *FORMAT is updated to point just after it. */
static int
-maybe_read_dollar_number (int *status, const char **format,
+maybe_read_dollar_number (const char **format,
int dollar_needed, tree params, tree *param_ptr,
const format_kind_info *fki)
{
{
if (dollar_needed)
{
- status_warning (status, "missing $ operand number in format");
+ warning ("missing $ operand number in format");
return -1;
}
else
{
if (dollar_needed)
{
- status_warning (status, "missing $ operand number in format");
+ warning ("missing $ operand number in format");
return -1;
}
else
*format = fcp + 1;
if (pedantic && !dollar_format_warned)
{
- status_warning (status,
- "%s does not support %%n$ operand number formats",
- C_STD_NAME (STD_EXT));
+ warning ("%s does not support %%n$ operand number formats",
+ C_STD_NAME (STD_EXT));
dollar_format_warned = 1;
}
if (overflow_flag || argnum == 0
|| (dollar_first_arg_num && argnum > dollar_arguments_count))
{
- status_warning (status, "operand number out of range in format");
+ warning ("operand number out of range in format");
return -1;
}
if (argnum > dollar_max_arg_used)
&& dollar_arguments_used[argnum - 1] == 1)
{
dollar_arguments_used[argnum - 1] = 2;
- status_warning (status,
- "format argument %d used more than once in %s format",
- argnum, fki->name);
+ warning ("format argument %d used more than once in %s format",
+ argnum, fki->name);
}
else
dollar_arguments_used[argnum - 1] = 1;
a $; give a diagnostic and return true if it does, false otherwise. */
static bool
-avoid_dollar_number (int *status, const char *format)
+avoid_dollar_number (const char *format)
{
if (!ISDIGIT (*format))
return false;
format++;
if (*format == '$')
{
- status_warning (status,
- "$ operand number used after format"
- " without operand number");
+ warning ("$ operand number used after format without operand number");
return true;
}
return false;
pointers. */
static void
-finish_dollar_format_checking (int *status, format_check_results *res, int pointer_gap_ok)
+finish_dollar_format_checking (format_check_results *res, int pointer_gap_ok)
{
int i;
bool found_pointer_gap = false;
|| dollar_arguments_pointer_p[i]))
found_pointer_gap = true;
else
- status_warning (status, "format argument %d unused before used argument %d in $-style format",
- i + 1, dollar_max_arg_used);
+ warning ("format argument %d unused before used argument %d in $-style format",
+ i + 1, dollar_max_arg_used);
}
}
if (found_pointer_gap
PARAMS is the list of argument values. */
static void
-check_format_info (int *status, function_format_info *info, tree params)
+check_format_info (function_format_info *info, tree params)
{
format_check_context format_ctx;
unsigned HOST_WIDE_INT arg_num;
format_ctx.res = &res;
format_ctx.info = info;
format_ctx.params = params;
- format_ctx.status = status;
check_function_arguments_recurse (check_format_arg, &format_ctx,
format_tree, arg_num);
/* For strftime-like formats, warn for not checking the format
string; but there are no arguments to check. */
if (warn_format_nonliteral)
- status_warning (status, "format not a string literal, format string not checked");
+ warning ("format not a string literal, format string not checked");
}
else if (info->first_arg_num != 0)
{
++arg_num;
}
if (params == 0 && (warn_format_nonliteral || warn_format_security))
- status_warning (status, "format not a string literal and no format arguments");
+ warning ("format not a string literal and no format arguments");
else if (warn_format_nonliteral)
- status_warning (status, "format not a string literal, argument types not checked");
+ warning ("format not a string literal, argument types not checked");
}
}
case of extra format arguments. */
if (res.number_extra_args > 0 && res.number_non_literal == 0
&& res.number_other == 0 && warn_format_extra_args)
- status_warning (status, "too many arguments for format");
+ warning ("too many arguments for format");
if (res.number_dollar_extra_args > 0 && res.number_non_literal == 0
&& res.number_other == 0 && warn_format_extra_args)
- status_warning (status, "unused arguments in $-style format");
+ warning ("unused arguments in $-style format");
if (res.number_empty > 0 && res.number_non_literal == 0
&& res.number_other == 0 && warn_format_zero_length)
- status_warning (status, "zero-length %s format string",
- format_types[info->format_type].name);
+ warning ("zero-length %s format string",
+ format_types[info->format_type].name);
if (res.number_wide > 0)
- status_warning (status, "format is a wide character string");
+ warning ("format is a wide character string");
if (res.number_unterminated > 0)
- status_warning (status, "unterminated format string");
+ warning ("unterminated format string");
}
/* Callback from check_function_arguments_recurse to check a
format_check_results *res = format_ctx->res;
function_format_info *info = format_ctx->info;
tree params = format_ctx->params;
- int *status = format_ctx->status;
int format_length;
HOST_WIDE_INT offset;
will decrement it if it finds there are extra arguments, but this way
need not adjust it for every return. */
res->number_other++;
- check_format_info_main (status, res, info, format_chars, format_length,
+ check_format_info_main (res, info, format_chars, format_length,
params, arg_num);
}
argument in the list of arguments. */
static void
-check_format_info_main (int *status, format_check_results *res,
+check_format_info_main (format_check_results *res,
function_format_info *info, const char *format_chars,
int format_length, tree params,
unsigned HOST_WIDE_INT arg_num)
if (*format_chars == 0)
{
if (format_chars - orig_format_chars != format_length)
- status_warning (status, "embedded %<\\0%> in format");
+ warning ("embedded %<\\0%> in format");
if (info->first_arg_num != 0 && params != 0
&& has_operand_number <= 0)
{
res->number_extra_args++;
}
if (has_operand_number > 0)
- finish_dollar_format_checking (status, res, fki->flags & (int) FMT_FLAG_DOLLAR_GAP_POINTER_OK);
+ finish_dollar_format_checking (res, fki->flags & (int) FMT_FLAG_DOLLAR_GAP_POINTER_OK);
return;
}
if (*format_chars++ != '%')
continue;
if (*format_chars == 0)
{
- status_warning (status, "spurious trailing %<%%%> in format");
+ warning ("spurious trailing %<%%%> in format");
continue;
}
if (*format_chars == '%')
is not used here, we can't immediately conclude this is a
format without them, since it could be printf %m or scanf %*. */
int opnum;
- opnum = maybe_read_dollar_number (status, &format_chars, 0,
+ opnum = maybe_read_dollar_number (&format_chars, 0,
first_fillin_param,
&main_arg_params, fki);
if (opnum == -1)
}
else if (fki->flags & FMT_FLAG_USE_DOLLAR)
{
- if (avoid_dollar_number (status, format_chars))
+ if (avoid_dollar_number (format_chars))
return;
}
*format_chars, NULL);
if (strchr (flag_chars, *format_chars) != 0)
{
- status_warning (status, "repeated %s in format", _(s->name));
+ warning ("repeated %s in format", _(s->name));
}
else
{
++format_chars;
if (*format_chars == 0)
{
- status_warning (status, "missing fill character at end of strfmon format");
+ warning ("missing fill character at end of strfmon format");
return;
}
}
if (has_operand_number != 0)
{
int opnum;
- opnum = maybe_read_dollar_number (status, &format_chars,
+ opnum = maybe_read_dollar_number (&format_chars,
has_operand_number == 1,
first_fillin_param,
¶ms, fki);
}
else
{
- if (avoid_dollar_number (status, format_chars))
+ if (avoid_dollar_number (format_chars))
return;
}
if (info->first_arg_num != 0)
{
if (params == 0)
{
- status_warning (status, "too few arguments for format");
+ warning ("too few arguments for format");
return;
}
cur_param = TREE_VALUE (params);
}
if (found_width && !non_zero_width_char &&
(fki->flags & (int) FMT_FLAG_ZERO_WIDTH_BAD))
- status_warning (status, "zero width in %s format",
- fki->name);
+ warning ("zero width in %s format", fki->name);
if (found_width)
{
i = strlen (flag_chars);
flag_chars[i++] = fki->left_precision_char;
flag_chars[i] = 0;
if (!ISDIGIT (*format_chars))
- status_warning (status, "empty left precision in %s format",
- fki->name);
+ warning ("empty left precision in %s format", fki->name);
while (ISDIGIT (*format_chars))
++format_chars;
}
if (has_operand_number != 0)
{
int opnum;
- opnum = maybe_read_dollar_number (status, &format_chars,
+ opnum = maybe_read_dollar_number (&format_chars,
has_operand_number == 1,
first_fillin_param,
¶ms, fki);
}
else
{
- if (avoid_dollar_number (status, format_chars))
+ if (avoid_dollar_number (format_chars))
return;
}
if (info->first_arg_num != 0)
{
if (params == 0)
{
- status_warning (status, "too few arguments for format");
+ warning ("too few arguments for format");
return;
}
cur_param = TREE_VALUE (params);
{
if (!(fki->flags & (int) FMT_FLAG_EMPTY_PREC_OK)
&& !ISDIGIT (*format_chars))
- status_warning (status, "empty precision in %s format",
- fki->name);
+ warning ("empty precision in %s format", fki->name);
while (ISDIGIT (*format_chars))
++format_chars;
}
{
/* Warn if the length modifier is non-standard. */
if (ADJ_STD (length_chars_std) > C_STD_VER)
- status_warning (status, "%s does not support the %qs %s length modifier",
- C_STD_NAME (length_chars_std), length_chars,
- fki->name);
+ warning ("%s does not support the %qs %s length modifier",
+ C_STD_NAME (length_chars_std), length_chars,
+ fki->name);
}
}
{
const format_flag_spec *s = get_flag_spec (flag_specs,
*format_chars, NULL);
- status_warning (status, "repeated %s in format", _(s->name));
+ warning ("repeated %s in format", _(s->name));
}
else
{
|| (!(fki->flags & (int) FMT_FLAG_FANCY_PERCENT_OK)
&& format_char == '%'))
{
- status_warning (status, "conversion lacks type at end of format");
+ warning ("conversion lacks type at end of format");
continue;
}
format_chars++;
if (fci->format_chars == 0)
{
if (ISGRAPH(format_char))
- status_warning (status, "unknown conversion type character %qc in format",
+ warning ("unknown conversion type character %qc in format",
format_char);
else
- status_warning (status, "unknown conversion type character 0x%x in format",
+ warning ("unknown conversion type character 0x%x in format",
format_char);
continue;
}
if (pedantic)
{
if (ADJ_STD (fci->std) > C_STD_VER)
- status_warning (status, "%s does not support the %<%%%c%> %s format",
- C_STD_NAME (fci->std), format_char, fki->name);
+ warning ("%s does not support the %<%%%c%> %s format",
+ C_STD_NAME (fci->std), format_char, fki->name);
}
/* Validate the individual flags used, removing any that are invalid. */
continue;
if (strchr (fci->flag_chars, flag_chars[i]) == 0)
{
- status_warning (status, "%s used with %<%%%c%> %s format",
- _(s->name), format_char, fki->name);
+ warning ("%s used with %<%%%c%> %s format",
+ _(s->name), format_char, fki->name);
d++;
continue;
}
{
const format_flag_spec *t;
if (ADJ_STD (s->std) > C_STD_VER)
- status_warning (status, "%s does not support %s",
- C_STD_NAME (s->std), _(s->long_name));
+ warning ("%s does not support %s",
+ C_STD_NAME (s->std), _(s->long_name));
t = get_flag_spec (flag_specs, flag_chars[i], fci->flags2);
if (t != NULL && ADJ_STD (t->std) > ADJ_STD (s->std))
{
? t->long_name
: s->long_name);
if (ADJ_STD (t->std) > C_STD_VER)
- status_warning (status, "%s does not support %s with the %<%%%c%> %s format",
- C_STD_NAME (t->std), _(long_name),
- format_char, fki->name);
+ warning ("%s does not support %s with the %<%%%c%> %s format",
+ C_STD_NAME (t->std), _(long_name),
+ format_char, fki->name);
}
}
}
if (bad_flag_pairs[i].ignored)
{
if (bad_flag_pairs[i].predicate != 0)
- status_warning (status, "%s ignored with %s and %<%%%c%> %s format",
- _(s->name), _(t->name), format_char,
- fki->name);
+ warning ("%s ignored with %s and %<%%%c%> %s format",
+ _(s->name), _(t->name), format_char,
+ fki->name);
else
- status_warning (status, "%s ignored with %s in %s format",
- _(s->name), _(t->name), fki->name);
+ warning ("%s ignored with %s in %s format",
+ _(s->name), _(t->name), fki->name);
}
else
{
if (bad_flag_pairs[i].predicate != 0)
- status_warning (status, "use of %s and %s together with %<%%%c%> %s format",
- _(s->name), _(t->name), format_char,
- fki->name);
+ warning ("use of %s and %s together with %<%%%c%> %s format",
+ _(s->name), _(t->name), format_char,
+ fki->name);
else
- status_warning (status, "use of %s and %s together in %s format",
- _(s->name), _(t->name), fki->name);
+ warning ("use of %s and %s together in %s format",
+ _(s->name), _(t->name), fki->name);
}
}
else if (strchr (fci->flags2, '2') != 0)
y2k_level = 2;
if (y2k_level == 3)
- status_warning (status, "%<%%%c%> yields only last 2 digits of year in some locales",
- format_char);
+ warning ("%<%%%c%> yields only last 2 digits of year in some locales",
+ format_char);
else if (y2k_level == 2)
- status_warning (status, "%<%%%c%> yields only last 2 digits of year", format_char);
+ warning ("%<%%%c%> yields only last 2 digits of year", format_char);
}
if (strchr (fci->flags2, '[') != 0)
++format_chars;
if (*format_chars != ']')
/* The end of the format string was reached. */
- status_warning (status, "no closing %<]%> for %<%%[%> format");
+ warning ("no closing %<]%> for %<%%[%> format");
}
wanted_type = 0;
wanted_type_std = fci->types[length_chars_val].std;
if (wanted_type == 0)
{
- status_warning (status, "use of %qs length modifier with %qc type character",
- length_chars, format_char);
+ warning ("use of %qs length modifier with %qc type character",
+ length_chars, format_char);
/* Heuristic: skip one argument when an invalid length/type
combination is encountered. */
arg_num++;
if (params == 0)
{
- status_warning (status, "too few arguments for format");
+ warning ("too few arguments for format");
return;
}
params = TREE_CHAIN (params);
&& ADJ_STD (wanted_type_std) > ADJ_STD (fci->std))
{
if (ADJ_STD (wanted_type_std) > C_STD_VER)
- status_warning (status, "%s does not support the %<%%%s%c%> %s format",
- C_STD_NAME (wanted_type_std), length_chars,
- format_char, fki->name);
+ warning ("%s does not support the %<%%%s%c%> %s format",
+ C_STD_NAME (wanted_type_std), length_chars,
+ format_char, fki->name);
}
}
if (main_arg_num != 0)
{
if (suppressed)
- status_warning (status, "operand number specified with suppressed assignment");
+ warning ("operand number specified with suppressed assignment");
else
- status_warning (status, "operand number specified for format taking no argument");
+ warning ("operand number specified for format taking no argument");
}
}
else
++arg_num;
if (has_operand_number > 0)
{
- status_warning (status, "missing $ operand number in format");
+ warning ("missing $ operand number in format");
return;
}
else
has_operand_number = 0;
if (params == 0)
{
- status_warning (status, "too few arguments for format");
+ warning ("too few arguments for format");
return;
}
}
}
if (first_wanted_type != 0)
- check_format_types (status, first_wanted_type);
+ check_format_types (first_wanted_type);
}
}
/* Check the argument types from a single format conversion (possibly
including width and precision arguments). */
static void
-check_format_types (int *status, format_wanted_type *types)
+check_format_types (format_wanted_type *types)
{
for (; types != 0; types = types->next)
{
&& i == 0
&& cur_param != 0
&& integer_zerop (cur_param))
- status_warning (status,
- "writing through null pointer (arg %d)",
- arg_num);
+ warning ("writing through null pointer (arg %d)",
+ arg_num);
/* Check for reading through a NULL pointer. */
if (types->reading_from_flag
&& i == 0
&& cur_param != 0
&& integer_zerop (cur_param))
- status_warning (status,
- "reading through null pointer (arg %d)",
- arg_num);
+ warning ("reading through null pointer (arg %d)",
+ arg_num);
if (cur_param != 0 && TREE_CODE (cur_param) == ADDR_EXPR)
cur_param = TREE_OPERAND (cur_param, 0);
&& (TREE_CODE_CLASS (TREE_CODE (cur_param)) == 'c'
|| (DECL_P (cur_param)
&& TREE_READONLY (cur_param))))))
- status_warning (status, "writing into constant object (arg %d)", arg_num);
+ warning ("writing into constant object (arg %d)", arg_num);
/* If there are extra type qualifiers beyond the first
indirection, then this makes the types technically
&& (TYPE_READONLY (cur_type)
|| TYPE_VOLATILE (cur_type)
|| TYPE_RESTRICT (cur_type)))
- status_warning (status, "extra type qualifiers in format argument (arg %d)",
+ warning ("extra type qualifiers in format argument (arg %d)",
arg_num);
}
else
{
if (types->pointer_count == 1)
- status_warning (status, "format argument is not a pointer (arg %d)", arg_num);
+ warning ("format argument is not a pointer (arg %d)", arg_num);
else
- status_warning (status, "format argument is not a pointer to a pointer (arg %d)", arg_num);
+ warning ("format argument is not a pointer to a pointer (arg %d)", arg_num);
break;
}
}
&& strcmp (types->wanted_type_name, that) != 0)
this = types->wanted_type_name;
if (types->name != 0)
- status_warning (status, "%s is not type %s (arg %d)", types->name, this,
+ warning ("%s is not type %s (arg %d)", types->name, this,
arg_num);
else
- status_warning (status, "%s format, %s arg (arg %d)", this, that, arg_num);
+ warning ("%s format, %s arg (arg %d)", this, that, arg_num);
}
}
}