« Bad arguments returning from function »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 10:43pm

ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Bad arguments returning from function  (Read 177 times)
New Member

member is offline



Posts: 12
xx Bad arguments returning from function
« Thread started on: Oct 13th, 2017, 11:48pm »

Now I've got a keyboard, I've been doing some detailed programming and experimenting - I've managed to crash BASIC on my Android about a dozen times so far today, but that could be the tablet itself.

I've been staring at this code and feel I'm missing something obvious. This is the smallest snippet* from a program that demos my File Picker that encounters the bug.

If I do cls%=FNs(FNfile_highlight(fg%,128+bg%))<>"." I get Bad arguments at line 100. If I spit the code into two statements A$=FNfile_highlight(fg%,128+bg%):cls%=FNs(A$)<>"." I don't. Also, if I remove the A$=A$+CHR$B% in the subroutine I don't get the error.
The code works perfectly on BB4W and RISC OS. I'm stumped!

   10 fg%=7:bg%=0
   30 cls%=FNs(FNfile_highlight(fg%,128+bg%))<>"."
   40 REM A$=FNfile_highlight(fg%,128+bg%):cls%=FNs(A$)<>"."
   50 END
   70 DEFFNfile_highlight(C%,B%)
   80 A$=""
   90 B%=FNscrnchr:VDU B%:A$=A$+CHR$B%
  100 =A$
  110 :
  140 DEFFNscrnchr:A%=135:=((USR&FFF4)AND&FF00)DIV256
  150 :
  160 DEFFNs(A$)
  170 WHILE LEFT$(A$,1)=" ":A$=MID$(A$,2):ENDWHILE
  180 WHILE RIGHT$(A$,1)=" ":A$=LEFT$(A$,LENA$-1):ENDWHILE
  190 =A$ 

*Actually, it's just occured to me that I haven't tested using DEFFNs(A$)=A$ but my battery is flat at the moment.

This is reminding me of the Spectrum SCREEN$ bug where you couldn't do A$=A$+SCREEN$(x,y).
User IP Logged

Richard Russell

member is offline


Homepage PM

Posts: 803
xx Re: Bad arguments returning from function
« Reply #1 on: Oct 14th, 2017, 11:02am »

on Oct 13th, 2017, 11:48pm, jgharston wrote:
The code works perfectly on BB4W and RISC OS. I'm stumped!

You say it "works perfectly on BB4W" but it doesn't: it gives rise to an 'Incorrect arguments at line 30' error message! You should be well aware of the cause because it was discussed at great length in the Bug alert thread of earlier in the year (it didn't turn out to be a bug at all of course, but the misleading thread title remains).

I'm not going to go over old ground again, especially as it's a complex issue, but the underlying fault in your code is that you have a 'local' variable that is not declared LOCAL, specifically A$ in FNfile_highlight(). In itself the absence of the LOCAL wouldn't cause a problem (apart from corrupting a global variable unnecessarily) but it does cause a problem when the function concerned is used as a parameter - because now A$ is corrupted at a point when it mustn't be.

So the solution is to add a LOCAL A$ (say as line 75). However I am quite concerned that you are reporting that you don't receive an error message from BB4W: that might suggest that you are still using a version prior to 6.10a. In those versions the fault in your program will cause BBC BASIC to enter an unstable state internally, with potentially serious consequences at some (apparently unrelated) later time - which of course is exactly what the person who originally discovered and reported the issue found.

It's noteworthy that a subtle difference between BBC BASIC running on Windows and on Android is that the former reports the 'Incorrect arguments' error at line 30 and the latter at line 100. It's debateable which is more 'useful' because you can think of the cause as being either that FNfile_highlight() is used as a parameter or that it is missing an essential LOCAL. It's the combination of the two that results in BBC BASIC entering an unstable state.


« Last Edit: Oct 14th, 2017, 3:42pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls