|
Forum Index : Microcontroller and PC projects : Is this a bug??
| Author | Message | ||||
| erbp Senior Member Joined: 03/05/2016 Location: AustraliaPosts: 195 |
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: GermanyPosts: 1671 |
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: AustraliaPosts: 195 |
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: AustraliaPosts: 3308 |
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: GermanyPosts: 1671 |
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: GermanyPosts: 1671 |
This bug is eliminated with MX 170-28/MM V5.04.07 Thanks Geoff! causality ≠ correlation ≠ coincidence |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |