Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-04

adhoc string bugs in 1.0.6 pre2 (not sure though)

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi, I've made a little study of errors related to strings, and specially with string length. There's an attach with all the examples cited below for you not to copy-paste the examples again.

I'm sorry if

attachments are not permitted in this list.
I should use the bug webpage instead.

I think that I'm doing right sending the bugs here, they're related and string is an important thing I think.

adrian15.

Here goes the bugs (some of them may not be bugs, sorry then):

Hi, I want to comment some bugs or perhaps misconceptions on 1.0.6 snapshot for DosGo32v2.
I download them 17 April 2002.

This program (test1.pas) generates an error when compiling:

program myprogram;
const
mynumber=30000000000000;
var
mystring : string[300*mynumber];
begin
write('Hello world');
end.

Error for test1.pas when compiling is the following:

test1.pas(9,31) Error: Illegal expression
test1.pas(9,31) Error: string length must be a value from 1 to 255
test1.pas(15) Fatal: There were 2 errors compiling module, stopping

What I find erroneous is: "value from 1 to 255" because I think that a string length now can be more than 255 isn't it?

This program (test2.pas) doesn't generate an error when compiling:

program myprogram;
const
mynumber=3000;
var
mystring : string[300*mynumber];
begin
write('Hello world');
end.

So I suppose that strings over 255 are allowed.

This program (test3.pas) tried to see the length of the string, I don't know how to do it.
Please just change the line to see the string length and tell us the errors if there are any.

program myprogram;
const
mynumber=3000;
var
mystring : string[300*mynumber];
begin
write('Hello world');
write('Length of string is: ',mystring.length());
end.

This program (test4.pas)
its_the_access_to_array_position_shouldnt_be_processed_as_an_index_out_of_array_ error
shows an error (I don't remember which) but the thing is that it doesn't show the error
as a "fatal string exceeds line" but I think there was a runtime error. Oh shit, I don't remember.

program myprogram;
const
mynumber=3000;
var
mystring : string[300*mynumber];
myvarnumber : longint;
begin
myvarnumber:=3000000*mynumber;
writeln('Hello world');
writeln('Is it perhaps the myvarnumber alone: ',myvarnumber);
writeln('It is the access to the string', mystring[myvarnumber]);
end.

Note after another compiling comenting the third writeln line I determined that the error was given because of this third writeln line, e.g., acceding to mystring[myvarnumber]

This program (test5.pas) comes to show that test4.pas isn't right because here the problem is treated in another way: The error is "fatal string exceeds line".

program myprogram;
const
mynumber=3000;
var
mystring : string[300*mynumber];
myvarnumber : longint;
begin
myvarnumber:=3000000*mynumber;
writeln('Hello world');
writeln('Is it perhaps the myvarnumber alone: ',myvarnumber);
writeln('what happens if we put
        the number itself: ', mystring[410065408]);
end.

This program (test6.pas) causes a runtime error 216. Shouldn't be treated as a index out of
string length error or similar?

program myprogram;
const
mynumber=3000;
var
mystring : string[300*mynumber];
myvarnumber : longint;
begin
myvarnumber:=3000000*mynumber;
writeln('Hello world');
writeln('Position', myvarnumber, 'of the string is: ',mystring[myvarnumber]);
end.

This program (test7.pas) I suppose that works in 1.0.4 version. But I'm sure that doesn't work in this version.

Is it right because of Delphi compatibility or not?

program myprogram;
const
mynumber=3000;
var
mystring : string[300*mynumber];
begin
write('Hello world');
write('Length of string is: ',length(mystring);
end.

That's all. I have no time I think you should try similar examples but trying with arrays instead of string. In my examples you could change mystring : string[300*mynumber]; line and put:

mystring: array [1..300*mynumber] of integer;

and see what happens. I have no time for doing it.

My conclusion is that you have some problem when processing expressions that results in a number instead than a number itself that points to an array position. (index instead of position is a better word perhaps?)

That's to say test4.pas and test4.pas do the same thing but the error is processed in another way.

Perhaps this ad-hoc made errors are errors that should happen usually but... I have the hope that some of them are real errors and that this message isn't wasting your time.

See you,

adrian15.

---------------------------------------------
This message was sent using Endymion MailMan.
http://www.endymion.com/products/mailman/

Reply by email

Peter Vreman
Hi, I've made a little study of errors related to strings, and specially with string length. There's an attach with all the examples cited below for you not to copy-paste the examples again.

I don't have the time at the moment to test the bugs. But Did you use -Sh or -Sd on the commandline to turn on ansistrings? Else you are using standard pascal strings that can be only 255 chars long.

Reply by email

Unknown author

But Did you use -Sh or -Sd on the
commandline to turn on ansistrings?

The commandline that I used was:

fpc pru.pas

(pru.pas was my test file)

Else you are using standard pascal strings that can be only 255 chars long.

So you mean that if -Sh or -Sr are activated I'm using ansistrings but

if they aren't activated (which is my case) I'm using standard pascal string which can't be longer than 255 chars.

If I've interpreted ok your words,... this example below:

program myprogram;
var
mystring : string[300];
begin
write('Hello world');
end.
should provoque/generate an error but doesn't. (I really don't remember if I've
tested it or not but I think so.) Is this perhaps a bug?

Another example of the same thing is my test2.pas.

Hoping that we are nearer to a bug,

adrian15.

---------------------------------------------
This message was sent using Endymion MailMan.
http://www.endymion.com/products/mailman/

Reply by email