delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/08/23/09:24:33

Date: Sun, 23 Aug 1998 16:23:29 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Robert Hoehne <robert DOT hoehne AT gmx DOT net>
cc: djgpp-workers <djgpp-workers AT delorie DOT com>
Subject: Re: Bug in crt1.c (alpha 980712)
In-Reply-To: <35DFED7B.6AC8212D@gmx.net>
Message-ID: <Pine.SUN.3.91.980823161841.1451A-100000@is>
MIME-Version: 1.0

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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019