Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

does bascom check for max stringlength

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051
View previous topic :: View next topic  
Author Message
RAWWAR

Bascom Member



Joined: 26 Nov 2014
Posts: 13

PostPosted: Wed Nov 26, 2014 9:47 pm    Post subject: does bascom check for max stringlength Reply with quote

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 ?

Rob
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5069
Location: Holland

blank.gif
PostPosted: Wed Nov 26, 2014 9:59 pm    Post subject: Reply with quote

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
Back to top
View user's profile Visit poster's website
RAWWAR

Bascom Member



Joined: 26 Nov 2014
Posts: 13

PostPosted: Thu Nov 27, 2014 11:44 pm    Post subject: Reply with quote

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
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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