Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String Issues
#1
I'm having a weird issue. I have the following code setting a string:
Code:
IF currentMatchType=FACUP then let faCupMatchCountString="Round "+STR$(faCupMatchCount) IF faCupMatchCount=7 Then let faCupMatchCountString="Semi-Final" ELSEIF faCupMatchCount=8 Then let faCupMatchCountString="Final" END IF

Later on it prints that string. On a 1-6 it prints "Round 1" / "Round 2" and so on. As soon as the FaCupMatchCount hits 7 it prints gibberish and/or crashes...


Is there a potential issue in the string handling, or have I written more notoriously bad code?

The thing is, it works for the earlier numbers...
(yes, I can provide the whole program again if you wish... It's sometimes difficult to tell if I've done something amiss, or the compiler has - we've had array bounds checking issues already!)

If I change the code so both Ifs say "8" then it prints "Round 7" as expected, and then prints gibberish instead of "Final"

Here's the code that actually prints it at the point that it fails:
Code:
if currentMatchType=FACUP then print "F.A.Cup Match - ";faCupMatchCountString else PRINT "League Match - "; IF division=4 then print "League 2" elseif division=3 then print "League 1" elseif division=2 then print "Championship" else print "Premier League" END IF END IF

It prints "F.A. Cup Match - " and then gibberish on the screen.
Reply
#2
I tried to replicate this with a smaller program, and couldn't. The small one works perfectly.

*growl* The thing is, I know it's on a "print" command that it's failing, and I don't know HOW that could fail as a programmer error for print a string directly.

My best suspect right now is the bigger string isn't moving up the requisite amount of memory.

To test his, I tried making it assign " ROUND" instead (start with a longer string), and that didn't help. I asked it to also print the length of the string. It was the expected 17 each time until cycle 7, then the string was listed as 64,847 characters long; which is hopelessly wrong.

The test code below works, so it doesn't show the failure Sad It DOES use identical code as the one that fails for setting and testing, however. *grr*

Perhaps what I'm showing more than anything, is that we need better testing for out of bounds or memory overwriting. Sad I don't know if this is my error.

Code:
#DEFINE FACUP 1 dim currentMatchType, faCupMatchCount, division as uByte dim faCupMatchCountString as string currentMatchType=FACUP let faCupMatchCount=1 let division=4 FUNCTION get () as uByte DIM lastK AS uByte AT 23560: REM LAST_K System VAR LET lastK=0 DO LOOP until lastK <> 0 : REM Wait FOR a keypress RETURN lastK END FUNCTION cls do IF currentMatchType=FACUP then let faCupMatchCountString="Round "+STR$(faCupMatchCount) IF faCupMatchCount=7 Then let faCupMatchCountString="Semi-Final" ELSEIF faCupMatchCount=8 Then let faCupMatchCountString="Final" END IF end if IF currentMatchType=FACUP then print "F.A.Cup Match - ";faCupMatchCountString else PRINT "League Match - "; IF division=4 then print "League 2" elseif division=3 then print "League 1" elseif division=2 then print "Championship" else print "Premier League" END IF END IF if faCupMatchCount=9 then stop else faCupMatchCount=faCupMatchCount+1 end if get() loop
Reply
#3
I agree. I'm currently working on implementing bitwise instructions (bAND, bOR, bNOT, bXOR, bSET, bRESET, bTEST), and the boolean XOR. Other than that there won't be new features in 1.2.6 except array boundary and out of memory checking. Once implemented we can discard many problems and locate the bug much faster regardless it's on your program or the compiler.
Reply
#4
That's awesome.

I'll hang in for that, then. Thankyou!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)