Problems with strings in GPC beta 971001_(re)

Thu, 23 Oct 1997 02:42:24 +0200



Jesper Lund wrote:

> I have encountered a couple problems with strings in the most recent GPC beta
> version.  Most of the problems are due to missing range checks, e.g. when
> assigning a string to a shorter string, or passing a string to a procedure
> with a shorter string as formal parameter.
> 
> 1) The program below illustrates some of these problems:

Yes, this is a known bug. I think it will be solved soon.

> 2) Another facet of the problem occurs when reading strings from a text file
> with Read[ln] (F, stringVar).
>
> If you call Readln, the program will read from the file until the next CR/LF,
> no matter the size (length) of stringVar, and try to copy the entire line to
> the variables stringVar (which will almost surely crash the program somehow;
> but not necessarily in the call to Readln. The SIGSEGV exception could come
> later, and with a stack trace which makes no sense). 

Strange! There has always been a check for the maximum length in the read[ln]
procedure.

> On the other hand, Read (F, stringVar) only reads a maximum of
> Length(stringVar) characters [as it should].

Even more strange, since Read and Readln are actually the same procedure
(or rather function) internally. Readln (F, stringVar) first does exactly the
same as Read (F, stringVar), and then a Readln (stringVar).

Perhaps something was broken temporarily while I changed other things in the
Read/Write procedures. OTOH, the following program works correctly (i.e.
outputs only 5 characters, even if I type more than 5) on my Linux GPC (which
has been modified somewhat after 971001) as well as on my DJGPP GPC (which is
the original 971001 binary distribution):

program x;
var s:string(5);
begin
  readln(s);
  writeln(s)
end.

Perhaps you did some other thing in your program that triggered the first bug?
If not, please send me a program and sample input to show this problem.

-- 
Frank Heckenbach, Erlangen, Germany
heckenb@mi.uni-erlangen.de
http://home.pages.de/~fjf/links.htm


Frank Heckenbach (heckenb@mi.uni-erlangen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es