This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning for unadorned 0 in varargs lists?


On Mon, 23 Aug 2004, Kaveh R. Ghazi wrote:

> 	void foo (char *, ...) __attribute__ ((__sentinel__, 1));
> 
> and a function call:
> 
> 	foo ("blah", "blah", NULL, NULL, NULL);
> 	foo ("blah", "blah", NULL, NULL, "blah");
> 
> you're saying that the above should get a warning for extra sentinel
> arguments and/or extra arguments after the supposed end position, but:
> 
> 	foo ("blah", "blah", "blah", NULL, NULL);
> 	foo (NULL, "blah", "blah", NULL, NULL);
> 
> would be okay.  Right?  If so I agree that your refined check is

Yes.  GCC should follow the same algorithm as the function is supposed to 
for locating the sentinel, i.e. the first NULL variadic argument.  It can 
then count the number of arguments afterwards; always warn for too few 
arguments afterwards, and optionally warn for too many.  It's natural to 
reuse -Wno-format-extra-args as the option to turn off warning for too 
many arguments.

> useful.  I would still suggest that the robustness of the checking be
> left as a followup refinement not a requirement for initial patch
> acceptance.  I don't want to discourage any one from working on it
> because the job is bigger than the itch they want to scratch.

Sure.  Format checking got to its current state through a long series of 
incremental changes and improvements.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]