Can someone tell me what I'm doing wrong?
Christopher R. Hertel
crh at nts.umn.edu
Wed May 23 15:33:45 GMT 2001
> >>>>> "CRH" == Christopher R Hertel <crh at nts.umn.edu> writes:
> CRH> The strncpy() copy function is *dangerous* because it does not guarantee
> CRH> that the target string will be NUL-terminated. You should always do this:
> CRH> strncpy( target, source, strlen(source) + 1 );
>
> 1) You mean :
>
> target[GETTING_SIZEOF_ TARGET_SOMEHOW( target ) - 1] = '\0';
> strncpy( target, source, GETTING_SIZEOF_ TARGET_SOMEHOW( target ) - 1 );
>
> is the safer way.
> # simply getting 'strlen(source)+1' means it's same as strcpy().
You are correct. I was thinking, however, that since constants were
being used this would not be required. You are also correct, though,
that using a strcpy() would be the same.
Chris -)-----
--
Christopher R. Hertel -)----- University of Minnesota
crh at nts.umn.edu Networking and Telecommunications Services
Ideals are like stars; you will not succeed in touching them
with your hands...you choose them as your guides, and following
them you will reach your destiny. --Carl Schultz
More information about the samba-technical
mailing list