[dpdk-dev] [PATCH 3/5] example_ip_pipeline: fix sizeof() on memcpy

Stephen Hemminger stephen at networkplumber.org
Wed Sep 9 20:47:30 CEST 2015


On Wed, 9 Sep 2015 18:25:53 +0000
"Dumitrescu, Cristian" <cristian.dumitrescu at intel.com> wrote:

> > diff --git a/examples/ip_pipeline/init.c b/examples/ip_pipeline/init.c
> > index 3f9c68d..75e3767 100644
> > --- a/examples/ip_pipeline/init.c
> > +++ b/examples/ip_pipeline/init.c
> > @@ -1325,7 +1325,7 @@ app_pipeline_type_cmd_push(struct app_params
> > *app,
> >  	/* Push pipeline commands into the application */
> >  	memcpy(&app->cmds[app->n_cmds],
> >  		cmds,
> > -		n_cmds * sizeof(cmdline_parse_ctx_t *));
> > +		n_cmds * sizeof(cmdline_parse_ctx_t));  
> 
> Actually no, as we are both the destination and the source of memcpy are array of pointers.
> 
> The source is a pipeline type, which is a static global data structure, so no issues with the life time of the data pointed to by the pointers.

In order to make tools happy, shouldn't the source and target be pointers to array of pointers.
In the current code
  &app->cmd[app->n_cmds] is type cmdline_parse_ctx_t *
  cmds is type cmdline_parse_ctx_t *

And type cmdline_parse_ctx_t is already a pointer.

Copying a set of pointers to pointers vs set of pointers will be the same since both are
the same size, but static checking tools see the problem.

This is why kernel developers particularly despise typedefs which hide
pointers like this one.


More information about the dev mailing list