Patch to add option -Wmissing-format-attribute

Joseph S. Myers jsm28@cam.ac.uk
Sat Sep 30 01:16:00 GMT 2000


On Fri, 29 Sep 2000, Richard Henderson wrote:

> Seems like you should also check that the current function
> is varargs.  Otherwise chances are that the va_list came
> from somewhere else.

I thought of doing that, but after grepping some code for vprintf found
there were also cases like the following I wanted to catch (with, in this
case, a second run with -Wmissing-format-attribute needed after adding the
first attribute it suggests):

void
vwarning (const char *fmt, va_list arg)
{
  fputs ("warning: ", stderr);
  vfprintf (stderr, fmt, arg);
  putc ('\n', stderr);
}

void
warning (const char *fmt, ...)
{
  va_list ap;
  va_start (ap, fmt);
  vwarning (fmt, ap);
  va_end (ap);
}

Observation suggests that vprintf functions are used in chains of
functions like the above as well as directly in warning() type
functions.  Format attributes are already meaningful on functions such as
vwarning() above; all they presently do is check the format string in the
rare cases that it is constant, but without suggesting the addition of
such an attribute to vwarning() it would never be detected that one was
appropriate for warning().

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc-patches mailing list