[dpdk-dev] [PATCH] net/ring: fix unchecked return value

David Marchand david.marchand at redhat.com
Wed Sep 23 11:43:31 CEST 2020


On Wed, Sep 23, 2020 at 11:39 AM Bruce Richardson
<bruce.richardson at 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.


-- 
David Marchand



More information about the dev mailing list