|
|
| Author |
Message |
drapal
Joined: 24 Jan 2006
Posts: 25
Location: Denver
|
|
Posted: 17 October 2006, 0:06 AM Post subject: Possible bug in structures with string member |
|
|
See the attached source. It crashes the ZX40. If I add more code, it will execute, but there is string corruption all over the place. Seems that it is related to AllocStr being on, and womething that looks like heap corruption.
Myron
| Description: |
| single code file, add to a default project and run. |
|
 Download |
| Filename: |
myproj.bas |
| Filesize: |
1.05 KB |
| Downloaded: |
2546 Time(s) |
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 17 October 2006, 2:35 AM Post subject: |
|
|
You are correct that the problem arises with an array of structures having a String member. The issue is not with string heap corruption, however. Rather, the problem is that the String members are not getting initialized properly. Only the String members of the first array element are initialized correctly. The String members of the remaining elements are not initialized. In this particular case, since the array was defined at the module level, the 4 bytes of storage for the string ends up being all zeroes, making the string look like a BasicX (statically allocated) string. That ends up causing lots of problems.
This problem has existed for some time; it was replicated using the v1.3.0 compiler as well.
One possible workaround is to temporarily switch to using bounded strings in the structure.
| Code: | Public Structure nvtable
Public i as Integer
Public s as BoundedString(25)
End Structure |
A second possible workaround is to temporarily add some code to properly initialize the allocated String elements. Here is a subroutine that initializes the String in each nvtable element of the array:
| Code: | Sub InitNVTable(ByRef tbl() as nvtable, ByVal elemCnt as Integer)
Dim i as byte
For i = 1 to CByte(elemCnt)
' set the string type for an allocated string
Call RamPoke(&He0, tbl(i).s.DataAddress + 1)
Next i
End Sub |
Then, somewhere early in your code add this call:
| Code: | | Call InitNVTable(table1, UBound(table1)) |
We believe that we know how to correct this problem but we have not yet implemented and tested the prospective solution.
|
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR
|
|
Posted: 18 October 2006, 0:18 AM Post subject: |
|
|
We have implemented and preliminarily tested the solution to this problem. You may try out the pre-release build if you'd like.
You can use this version of the compiler with older versions of the IDE but to do so you'll have to disable the insertion into the .zxb of the compilation target information. The compiler option to do that is shown below; add it near the top of your .pjt file.
|
|
| Back to top |
|
 |
|