[DONE] 1.875 (PB 4.20) - Invalid memory access

TailBite specific forum

Moderators: gnozal, ABBKlaus, lexvictory

Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

[DONE] 1.875 (PB 4.20) - Invalid memory access

Post by Mistrel »

This worked fine in 4.10 and whatever TailBite version I was using before.

TailBite code:

Code: Select all

ProcedureDLL.s TB_Test()
	ProcedureReturn "Anything"
EndProcedure
PureBasic code:

Code: Select all

Procedure This()
	Debug TB_Test()
EndProcedure ; crashes here

This()
It does not crash if it is not called from within a procedure:

Code: Select all

Debug TB_Test()
I think this is the same problem from this report:

http://www.purebasic.fr/english/viewtopic.php?t=30840
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

This problem is listed as "Done". However, I am having the same issue with tailbite. I keep getting "invalid memory access" errors, even with simple procedures. I am using the latest version of Tailbite and PB 4.2 (Windows XP pro and Vista Ultimate). Anyone else having this problem?
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Post by ABBKlaus »

npath wrote:This problem is listed as "Done". However, I am having the same issue with tailbite. I keep getting "invalid memory access" errors, even with simple procedures. I am using the latest version of Tailbite and PB 4.2 (Windows XP pro and Vista Ultimate). Anyone else having this problem?
You are propably calling some exported string functions from inside the library ?
But without a snippet i´m only guessing.
npath
User
User
Posts: 74
Joined: Tue Feb 15, 2005 5:15 pm

Post by npath »

I believe you are right. My problem is with this procedure:

Code: Select all

ProcedureDLL.l ParseString(stringToParse.s, arrayToFill.s(1), delimiter.s) ; Parse a string into an array using a delimiter. Returns count.
  ; Source: Uses code posted by pdwyer
  ; http://www.purebasic.fr/english/viewtopic.php?t=31044&highlight=split+string
 
  Structure MemoryArray
    Byte.c[0]
    word.w[0]
  EndStructure
  
  FindLen.l = Len(delimiter)
  MainLen.l = Len(stringToParse)
  arrayToFill.s(0)
  StringCount.l = 0
  
  *MainByteArray.MemoryArray = @stringToParse  ;*MainMem
  *FindByteArray.MemoryArray = @delimiter       ;*FindMem
  
  PrevPos.l = 1
  
  ; Build BadChr Array
  Dim BadChar.l(255)
  
  ; set all alphabet to max shift pos (length of find string plus 1)
  For i = 0 To 255
    BadChar(i)  =  FindLen + 1
  Next
  
  ;Update chars that are in the find string to their position from the end.
  For i = 0 To FindLen -1
    BadChar(*FindByteArray\Byte[i]) = FindLen - i   
  Next     
  
  MainArrayLoop.l = 1
  EndSearchPos.l = MainLen - (FindLen -1)
  
  While MainArrayLoop <= EndSearchPos
    
    If CompareMemory(@stringToParse + MainArrayLoop, @delimiter, FindLen) = 1
      FoundPos = MainArrayLoop + 1
      Redim arrayToFill.s(StringCount )
      
      ;emulate fast mid() function inline,
      If FoundPos - PrevPos > 0
        *RetMem = AllocateMemory(FoundPos - PrevPos)
        CopyMemory(@stringToParse + PrevPos -1, *RetMem, FoundPos - PrevPos)
        MidStr.s = PeekS(*RetMem,FoundPos - PrevPos)
        FreeMemory(*RetMem)
      Else
        MidStr.s = ""
      EndIf
      
      arrayToFill(StringCount) = MidStr
      StringCount = StringCount + 1
      PrevPos = FoundPos + FindLen
      
    EndIf
    ;Didn't find the string so shift as per the table.
    MainArrayLoop + BadChar(*MainByteArray.MemoryArray\Byte[MainArrayLoop + FindLen])
  Wend
  
  ;catch end
  Redim arrayToFill.s(StringCount)
  arrayToFill(StringCount) = Mid(stringToParse, PrevPos, MainLen - PrevPos +1)
  StringCount = StringCount + 1
  Redim arrayToFill.s(StringCount)
  
  ProcedureReturn StringCount 
EndProcedure
Post Reply