Posted: Wed Nov 26, 2014 9:47 pm Post subject: does bascom check for max stringlength
Hello,
I use the demoversion bascom 2.0.12.0 and I was wondering
if bascom checks if a typed string is not longer than assigned in the dim.
I used the following code as a test, because I had my doubts:
Dim Tekstbuf1 As Xram String * 8
Dim Tekstbuf2 As Xram String * 8
Dim Tekstbuf3 As Xram String * 8
Input "tekst1: " , Tekstbuf1
Input "tekst2: " , Tekstbuf2
Input "tekst3: " , Tekstbuf3
Print Tekstbuf1
Print Tekstbuf2
Print Tekstbuf3
Look what is printed when you enter a string which is longer than the 8 characters as indicated in the dim.
All entered strings have 11 characters instead of the max of 8:
tekst1: 1234567890-
tekst2: 1234567890+
tekst3: 1234567890=
result:
1234567891234567891234567890=
1234567891234567890
1234567891=
Am I doing something wrong ? Is this a bug in Bascom ?
Does this occur in the latest version as well ?
no there is no check for the length. it was designed this way. It would be simple to add it however if there would be enough interest for it. _________________ Mark
Mark,
Well.. if there is enough interest for it.... Error checking is done everywhere in bascom.
Try to assign a value like 1000 to a BYTE variable. Bascom reports that this is impossible.
I think it is not more than logic that if someone tries to put a string in a buffer which is
too small for it to hold the string, bascom should report that too.
In the present situation not only the string does not fit, also when it
is too long, it is no longer terminated with 00.
That is how I discovered it: I tried to read a string from assembler until 00, but it was never found.
Furthermore: other variables which are declared after the string variable(s) will be overwritten.
And since you say that it is simple to add it, why not do it ?
Regards,
Rob
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum