Changes to clitar.c: strcpy to pstrcpy ?

Jeremy Allison jallison at whistle.com
Fri May 15 16:37:18 GMT 1998


Richard Sharpe wrote:

> I notice that someone has carefully gone through clitar and changed every
> occurrence of strcpy to pstrcpy. I would prefer to use strncpy and strncat
> where needed, especially since I use dynamically allocated strings in clitar.
> 
> Are there any words of objection or caution?

Yes, that was me. Please don't use strncpy or strncat,
use safe_strcpy and safe_strcat instead.

The specs of strncpy and strncat insist that 'n'
(where n is the number of characters you set as
the limit) characters are actually copied, ie.
zero filled. This is very slow and why Andrew doesn't
want them in the Samba source.

safe_strcpy and safe_strcat will check for overflows
and have the same effect as strncpy and strncat, but
(a) zero terminate and (b) are faster. If you look
in smb.h you'll find pstrcpy #defined as 

#define pstrcpy(d,s) safe_strcpy((d),(s),sizeof(pstring)-1)

and the same for safe_strcat.

Cheers,

	Jeremy.

-- 
--------------------------------------------------------
Buying an operating system without source is like buying
a self-assembly Space Shuttle with no instructions.
--------------------------------------------------------


More information about the samba-technical mailing list