How can this error happen?
Pages: 1 2
nemo (145) 2546 posts |
That’s ki ni narimashita to you, Murray-kun. |
Steve Drain (222) 1620 posts |
@nemo I do not think there is anything I could possibly disagree with. Nevertheless, it is fun pushing the boundaries. ;-) |
Rick Murray (539) 13840 posts |
Yes, there’s a difference between encouraging and, well, playing.
Hai, senpai! ;-) |
Dave Higton (1515) 3526 posts |
Thread’s drifted a bit, annit? :-) Anyway: 7059 STOP has produced “Stopped” on a couple of occasions. So we’re further on and we’re no further on. There are no GOTOs in the code. You can see the previous lines in the code (and the last non-blank line before that is ENDPROC). So how can line 7059 be executed? |
Jeffrey Lee (213) 6048 posts |
A few things I can think of: Do you have anything that uses A% to Z%? For some silly reason BASIC doesn’t zero-initialise them on startup, so if you’ve got a code path which is reading from one of them before it’s been initialised then you could be getting some undefined behaviour from that (although it does seem a bit odd that it’s always the same place where it dies). Maybe try TRACE ON & TRACE OFF around the initialisation code as well? (assuming you can spool the output somewhere useful) Plus if you can get the output of LVAR when it fails then that might be useful (e.g. launch it via “*BASIC FooFile” rather than the default “*BASIC -quit FooFile”, so that you’re left in BASIC after it finishes) |
nemo (145) 2546 posts |
Dave admitted
Was the very first response not…?
If you can’t see the lack of
and that will allow you work back to where execution leaked from. |
nemo (145) 2546 posts |
Jeffrey said
Apropos of nothing, it is very important indeed to bear this in mind when using one of those BASIC compressors that renames variables. It is tempting to use a construction like this in a library or highly modular program:
This can lead to mystified disappointment when the compressor renames BTW, the ‘silly reason’ is that programs can pass integer values to the next program in the |
Martin Avison (27) 1494 posts |
@Dave
That was my first thought also. However,
But I would say it is perfectly possible. FNmin looks like a frequently used function, so when first used a% and b% would have been allocated variable space. That variable space is permanent, and will be re-used every time FNmin (or FNmax) is used. That means that there is plenty of time for something to overwrite the a% or b% variable space or even any of the chain of variable names starting in a and b that were allocated before a% and b%. Any time from first use to the errored use will do. The PROC will know where to put its parms without looking up the variable names, I think. If I was faced with that error (and I have had similar ones several times!) I would first try adding a line If the cause was still not obvious, I would write a small PROC which ran down the variable chain to find the missing variable, giving Reports and an error when it could not be found. This could be run at frequent intervals within the program, and after different pieces of code, to narrow down what code caused the variable to be lost. There is also a I suspect when the bug is found it will be obvious … finding it may take a while! Apologies if you are not using Reporter to help debugging a BASIC program! |
nemo (145) 2546 posts |
We have already established that execution is falling into the function:
|
Steve Drain (222) 1620 posts |
This is highly artificial and almost certainly does not represent what you have, but it does reproduce the error. PRINT FNmax(1,2) END 7040 DEFFNmax(A%,B%) 7050 IF A%>=B% THEN =A% ElSE =B% 7060 DEFFNmin(a%,b%) 7070 IF a%>=b% THEN =b% ELSE =a% It illustrates the clumsy way that BASIC interprets I do not think it can be the source of your error, but another possible problem is that BASIC searches for the next |
Martin Avison (27) 1494 posts |
I missed the STOP messages. If it can execute 7059, and it has not got there from a GOTO, then it seems it has fallen through 7050. However, if at that time it was in a Function, then it would have returned from the THEN or ELSE. If it was not in a Function, it would have errored at 7050 with ‘Not in a Function’. Something is not as it seems. We need to find how it arrived at the STOP. *ReportStack would display the current outstanding PROCs or FNs on the stack at that point. But I still bet on memory corruption somehow somewhere. |
nemo (145) 2546 posts |
There’s so many lovely little things like that, yes. I wonder if it’s a CC instead of an 8B. |
Chris Evans (457) 1614 posts |
What if it was somehow falling into the first DEF FN as well? |
Dave Higton (1515) 3526 posts |
Eventually I’ve found what’s going wrong. The code gets data in from a TCP socket. These data contain several text records, each terminated by CR. My code looks for the CR to determine how many bytes must be base64 decoded. However, in some cases the data are delivered to the app incomplete, so the CR hasn’t been delivered, so the search finds the first CR in goodness knows what data. The base64 decode then proceeds to decode 400-odd kbytes of data into an otherwise very generously sized 8kiB buffer. |
Pages: 1 2