Can someone tell me what I'm doing wrong?

Ray Van Dolson rayvd at bludgeon.org
Wed May 23 02:53:23 GMT 2001


Well... I changed this just in case, although it had worked previously
with this same bit of code... anyways, changed the strncpy line to account
for \0 and it still segfaults.  sigh... any other suggestions? :)

On Wed, 23 May 2001, Kenichi Okuyama wrote:

> Dear Ray-san,
>
> I don't know if this is the point. But this is what I found first.
>
> >>>>> "RVD" == Ray Van Dolson <rayvd at bludgeon.org> writes:
> RVD> #define WORKGROUP "STUDENTS"
> (skip)
> RVD>   strncpy(workgroup,WORKGROUP,8);
>
> According to my ANSI-C dictionary, strncpy will do the following.
>
> 1) strlen( "STUDENTS" ) returns 8, so total buffer size required to
>    copy "STUDENTS" to workgroup is *9*.
>
> 2) if given 3rd parameter which is allowed-copy-length is less then
>    source string length +1 ( +1 for termination ),
>    strncpy will make workgroup as follow:
>
>    { 'S', 'T', 'U', 'D', 'E', 'N', 'T', 'S' }
>
>    the key point is that we don't have '\0'.
>
> Maybe this is the point ( or something similar is ).
> ----
> Kenichi Okuyama
>





More information about the samba-technical mailing list