On Wed, Sep 23, 2020 at 11:43:31AM +0200, David Marchand wrote:
> On Wed, Sep 23, 2020 at 11:39 AM Bruce Richardson
> <bruce.richard...@intel.com> wrote:
> > I think a more standard way of checking for trailing chars is to use %n
> > which stores the number of chars processed. Then check that against
> > strlen.
> >
> > For example something like:
> >
> > if (sscanf(value, "%p%n", args, n) != 1 || n != strlen(value)) {
> >   /* do error handling */
> > }
> >
> 
> The man is a bit scary about %n:
> 
> The C standard says: "Execution of a %n directive does not increment
> the assignment count returned at the completion of execution" but the
> Corrigendum seems to contradict this.  Probably it is wise not to make
> any assumptions on the effect of %n conversions on the return value.
> 

That's not in the man page on my system (Ubuntu 20.04):

n     Nothing is expected; instead, the number of characters  consumed  thus  
far
      from  the input is stored through the next pointer, which must be a 
pointer
      to int.  This is not a conversion and does not increase the count  
returned
      by  the  function.  The assignment can be suppressed with the * 
assignment-
      suppression character, but the effect on the  return  value  is  
undefined.
      Therefore %*n conversions should not be used.

Reply via email to