BP.LET / SB.PUTP
Posted: Fri Aug 12, 2016 12:20 pm
Odd thing found when implementing function which returns changed parameters.
I soon discovered if you don't check name table that passed parameter is of correct type you can cause crash sometime:
MYFUNC(X%) : REMark is OK, but
MYFUNC(3) : REMark is not
Although both pass CA.GTINT as valid parameter, BP.LET with new value appears OK (no err_bp) but SuperBASIC causes memory corruption (eventually, if not immediately). I assumed the temporary name table entry for passed parameter (literal) would be discarded.
Solution of course, is to check name table that parameter passed is strictly an integer variable ($02x3) on entry (else reject) and then BP.LET is OK for system. So even
MYFUNC(X%) : REMark is rejected if X% unset, or
MYFUNC(X%+1) : REMark is rejected (integer expression)
But oddly, this is not rejected
MYFUNC(X%+Z%) : REMark where X% and Z% are set variables
It doesn't appear to cause same problem, even though strictly it is an integer expression (type $01x3). X% or Z% are not changed on return. The name table entry for X%+Z% is given as $02x3 !
BTW recently found nasty long time bug in SMSQ:
DIM a$(32767) : REMark is accepted (QDOS/Minerva only accepts <=32766)
a$='hello' : REMark bad, bad, bad!
Causes instant memory corruption.
I soon discovered if you don't check name table that passed parameter is of correct type you can cause crash sometime:
MYFUNC(X%) : REMark is OK, but
MYFUNC(3) : REMark is not
Although both pass CA.GTINT as valid parameter, BP.LET with new value appears OK (no err_bp) but SuperBASIC causes memory corruption (eventually, if not immediately). I assumed the temporary name table entry for passed parameter (literal) would be discarded.
Solution of course, is to check name table that parameter passed is strictly an integer variable ($02x3) on entry (else reject) and then BP.LET is OK for system. So even
MYFUNC(X%) : REMark is rejected if X% unset, or
MYFUNC(X%+1) : REMark is rejected (integer expression)
But oddly, this is not rejected
MYFUNC(X%+Z%) : REMark where X% and Z% are set variables
It doesn't appear to cause same problem, even though strictly it is an integer expression (type $01x3). X% or Z% are not changed on return. The name table entry for X%+Z% is given as $02x3 !
BTW recently found nasty long time bug in SMSQ:
DIM a$(32767) : REMark is accepted (QDOS/Minerva only accepts <=32766)
a$='hello' : REMark bad, bad, bad!
Causes instant memory corruption.