use of strncpy and strlen

Simo Sorce idra at samba.org
Thu Jan 17 05:55:06 GMT 2002


I have yet added a strnlen_w() function into HEAD some time ago, but it has been revelead not so usefull till now (see HEAD lib/util_unistr.c)

On Wed, Jan 16, 2002 at 06:05:31AM -0500, Green, Paul wrote:
> Some C/Unix implementations now have a "strnlen" function, which is a safe
> version of strlen. I'd be happy to contribute ours to Samba if you'd like
> it. You could then deprecate strlen via the usual macro trick.
> 
> PG
> --
> Paul Green, Senior Technical Consultant, Stratus Computer, Inc.
> Voice: +1 978-461-7557; FAX: +1 978-461-3610; Video on request.
> 
> 
> 
> -----Original Message-----
> From: jra at samba.org [mailto:jra at samba.org]
> Sent: Tuesday, January 15, 2002 8:11 PM
> To: Andrew Bartlett
> Cc: Benjamin Kuit; samba-technical at samba.org; jra at samba.org
> Subject: Re: use of strncpy and strlen
> 
> 
> On Wed, Jan 16, 2002 at 12:00:04PM +1100, Andrew Bartlett wrote:
> > Benjamin Kuit wrote:
> > > 
> > > Not sure if the respective developers are aware of the problem, but
> > > there are some occurances whereby people use Strncpy (or strncpy) with
> > > strlen like this:
> > > 
> > > Strncpy(dest, src, strlen(src));
> > > 
> > > Instead of using the size of the destination buffer for the length
> > > parameter.
> > > 
> > > The developers might aswell #undef strcpy and use it instead.
> > > 
> > > Just my 1 cents worth. =)
> > 
> > Yep, I fixed up a pile of these in passdb in HEAD, but they havn't made
> > it to 2.2 yet.
> > 
> > Can you give a list?  These need to be squahed...
> 
> Andrew,
> 
> 	When you do this - just remove StrnCpy and move to strlcpy -
> that way we can get rid of the annoying -1 also.
> 
> Jeremy.
> 

-- 
Simo Sorce       idra at samba.org
-------------------------------
Samba Team http://www.samba.org




More information about the samba-technical mailing list