Jo Dillon wrote:
Hi, I think I've found a bug in the latest beta snapshot of gpc (linked against gcc 2.8.1). Basically, when assigning one string to another the result seems to be a null string. A program that isolates the bug is included below:
No, it's not a GPC bug. The problem is the following line in your code:
r:=GetMem(sizeof(trec));
A (Pascal) string is a schema record type which has, besides the Length and the actual characters, a Capacity field which contains the maximum length of the string. When you declare a global or local string variable, or allocate a string via `New', the compiler will automatically set this field to the correct value. However, when you allocate the memory via `GetMem', the compiler does not know that there will be a string in the allocated memory, so it can't set the Capacity. Therefore, Capacity will contain the value that just happens to be in that memory location, in this case probably 0. So, the string will have a capacity of 0, i.e. it can't get longer than 0 chars.
To solve the problem, you could either set the Capacity manually (`r^.s.Capacity := 200;') -- but that's quite error-prone -- or just use `New(r);' instead of the GetMem statement -- which is IMHO easier and safer, anyway.
Frank
-- Frank Heckenbach, frank@fjf.gnu.de http://fjf.gnu.de/ PGP and GPG keys: http://fjf.gnu.de/plan