Date: Sun, 23 Aug 1998 16:23:29 +0300 (IDT) From: Eli Zaretskii To: Robert Hoehne cc: djgpp-workers Subject: Re: Bug in crt1.c (alpha 980712) In-Reply-To: <35DFED7B.6AC8212D@gmx.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Sun, 23 Aug 1998, Robert Hoehne wrote: > I don't know if the current behaviour is correct, but after > looking in the sources, I found, that strncpy copies > _ALWAYS_ as many characters as given in the third argument. This is ANSI requirement: strncpy should pad with zeroes if the second argument is shorter than what the third specifies. > Here we allocating memory with strlen(fc)+1 bytes. Let's say, > the fc is "foo.exe", then we allocating 8 bytes. > > strncpy(prog_name, fc, 16); > > Now we copying 16! bytes to progname. Then why not just calloc(17)? Or, better yet, use strncat? > And an other hint for Eli: Maybe it's a good idea to include > somewhere in the FAQ the trick I did above with the bsdmallo.c > (compiling with -DTEST -DRCHECK) since it seems to me good > technique to find memory corruptions in a program since it > will abort the program if you free a pointer which was illegal > overwriten (the memory it points to). Thanks, I will keep that in mind.