libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BUG in ltdl.c - here's a PATCH


From: Lutz Müller
Subject: Re: BUG in ltdl.c - here's a PATCH
Date: 14 Jun 2002 20:02:32 +0200

On Fri, 2002-06-14 at 19:49, Lutz Müller wrote:
> On Fri, 2002-06-14 at 18:23, Albert Chin wrote:
> > Shouldn't we find out why filename is non-zero terminated?
> 
> No, you didn't get it. If you do
> 
> strncpy (filename, dir_name, strlen (dir_name));
> 
> filename will afterwards not be terminated by '\0' (unless filename has
> previously been initialized to 0, for example by memset (filename, 0,
> ...)). If you copy a string, you need to copy the terminating '\0', too,
> i.e. 
> 
> strncpy (filename, dir_name, strlen (dir_name) + 1);

I think I know what causes the confusion. From the man page of strncpy
(i.e. http://www.tac.eu.org/cgi-bin/man-cgi?strncpy+3):

The strncpy() copies not more than len characters into dst, appending
`\0' characters if src is less than len characters long, and not
terminating dst if src is more than len characters long.

Of particular interest is the second part of the sentence.

Lutz
-- 
+----------------------------------------------+
| Lutz Müller                 +49 (7156) 34837 |
|                                              |
| Hans-Sachs-Strasse 5                         |
| 71254 Ditzingen       http://www.topfrose.de |
| Germany           address@hidden |
+----------------------------------------------+




reply via email to

[Prev in Thread] Current Thread [Next in Thread]