Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:19 10 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Is this a bug??

Author Message
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 01:40am 03 Nov 2017
Copy link to clipboard 
Print this post

I recently experienced corruption of data stored in arrays within a program I was working on. I have isolated it to calling a procedure and passing an array as the argument. I know the procedure arguments are passed by reference so any change made within the procedure will reflect in the data after returning from the procedure call. But in this case I can see the data being corrupted even when the procedure contains no code whatsoever.

Sub PassArray(TestArray() as String)
'do nothing
End Sub


So calling PassArray passing a string array as the argument results in the data in the array being corrupted after several call iterations. The first call is OK.

The screen shot below is from the ArrayTest program I have written to test/isolate this. It declares a 5 element string array (S$) and calls the PassArray procedure 5 times passing S$() each time and checks the contents of the array elements after each call.



Test iteration #1 reports no data corruption, iteration #2 reports corruption for the first 4 (of 5) of the array elements, and subsequent iterations report corruption for all 5 elements.

If there are multiple arrays declared (as there was in my original program), then all arrays seem to be affected even though only 1 has been used to pass in a procedure call. This happens even with a mix of String and Integer arrays and makes the results very confusing.

This is running on an E28 module with firmware 5.04.05, but I have also tested and found similar results on a Silicon Chip MX170 LCD Backpack Mk2.

The full listing of the test program source is below.

Option Explicit
Option Default Integer

Dim string ProgTitle$ = "Array Test"
Dim String ProgVer$ = "v1.0 - 03-Nov-2017"

'working variables
Dim Integer I

Dim String S$(4) 'String Array (5 array elements)

'initialize
Print "Starting " + ProgTitle$ + ": " + ProgVer$

'setup data in the String Array elements
S$(0) = "0"
S$(1) = "25"
S$(2) = "50"
S$(3) = "75"
S$(4) = "100"

Print "S$ = ";
For I = 0 to 4
Print S$(I) + " ";
Next I
Print ""

ArrayTest()

Print "End of ArrayTest Program"

End

Sub ArrayTest()
For I = 0 to 4
Print "Test Iteration #" + Str$((I + 1))

PassArray(S$())

CheckArrayValues()

Pause 1000
Next I
End Sub

Sub CheckArrayValues()
'verify array values - report if mismatch found

If S$(0) <> "0" Then
Print "S$(0) Value corrupted - Expected: 0, Actual: " + S$(0)
EndIf

If S$(1) <> "25" Then
Print "S$(1) Value corrupted - Expected: 25, Actual: " + S$(1)
EndIf

If S$(2) <> "50" Then
Print "S$(2) Value corrupted - Expected: 50, Actual: " + S$(2)
EndIf

If S$(3) <> "75" Then
Print "S$(3) Value corrupted - Expected: 75, Actual: " + S$(3)
EndIf

If S$(4) <> "100" Then
Print "S$(4) Value corrupted - Expected: 100, Actual: " + S$(4)
EndIf
End Sub

Sub PassArray(TestArray() as String)
'do nothing
End Sub
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 02:30am 03 Nov 2017
Copy link to clipboard 
Print this post

Yes, I think it is.

Maybe you can try a MMBasic V5.0.

This bug is already reported.

Regards
Michael
causality ≠ correlation ≠ coincidence
 
erbp
Senior Member

Joined: 03/05/2016
Location: Australia
Posts: 195
Posted: 02:34pm 03 Nov 2017
Copy link to clipboard 
Print this post

Hi Michael,

Thanks for confirming that it is a known issue. I do remember seeing your original thread now, but had forgotten about it (senior's moment ).

I do have a workaround for my original program that does not require passing the string array so am OK in that regard. I will re-test this when V5.04.06 is released.

Thanks,
Phil.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 03:52pm 03 Nov 2017
Copy link to clipboard 
Print this post

Yes, it is a known bug (the current DOS version of MMBasic already has this one fixed).

I have a small collection of bugs/issues to be sorted and I'm planning a new release in early December to fix them.

Geoff
Geoff Graham - http://geoffg.net
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 04:25pm 18 Dec 2017
Copy link to clipboard 
Print this post

Hi Geoff,

this bug is still alive! MX170-28/MM V5.04.06

Best regards


causality ≠ correlation ≠ coincidence
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 12:17pm 23 Dec 2017
Copy link to clipboard 
Print this post

This bug is eliminated with MX 170-28/MM V5.04.07

Thanks Geoff! Edited by twofingers 2017-12-24
causality ≠ correlation ≠ coincidence
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025