[dpdk-dev] [PATCH 09/18] drivers: net: qede: fix strncpy constant and NUL

Bruce Richardson bruce.richardson at intel.com
Tue May 8 21:53:15 CEST 2018


On Tue, May 08, 2018 at 05:59:47PM +0000, dev-bounces at dpdk.org wrote:
> 
> 
> > -----Original Message-----
> > From: dev <dev-bounces at dpdk.org> On Behalf Of Andy Green
> > Sent: Monday, May 7, 2018 11:30 PM
> > To: dev at dpdk.org
> > Subject: [dpdk-dev] [PATCH 09/18] drivers: net: qede: fix strncpy constant and
> > NUL
> > 
> > 
> > ---
> >  drivers/net/qede/base/ecore_int.c |   10 ++++++----
> >  1 file changed, 6 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/net/qede/base/ecore_int.c
> > b/drivers/net/qede/base/ecore_int.c
> > index f43781ba4..c809d84ef 100644
> > --- a/drivers/net/qede/base/ecore_int.c
> > +++ b/drivers/net/qede/base/ecore_int.c
> > @@ -1103,10 +1103,12 @@ static enum _ecore_status_t
> > ecore_int_deassertion(struct ecore_hwfn *p_hwfn,
> >  						OSAL_SNPRINTF(bit_name, 30,
> >  							      p_aeu->bit_name,
> >  							      num);
> > -					else
> > -						OSAL_STRNCPY(bit_name,
> > -							     p_aeu->bit_name,
> > -							     30);
> > +					else {
> > +						strncpy(bit_name,
> > +							p_aeu->bit_name,
> > +							sizeof(bit_name) - 1);
> > +						bit_name[sizeof(bit_name) - 1]
> > = '\0';
> > +					}
> 
> I think you can retain OSAL_STRNCPY and just replace 30 with 'bit_name[sizeof(bit_name) - 1'  and then set last byte with '\0' just like you did.

Can that actually be fixed inside OSAL_STRNCPY itself, rather than having
each use needing to explicitly null-terminate?


More information about the dev mailing list