Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Possible bug in structures with string member

 
Post new topic   Reply to topic    Forum Index -> ZX-40
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 Reply with quote

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



myproj.bas
 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: Reply with quote

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: Reply with quote

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.
Code:
--no-add-target
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZX-40 Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group