Bug, or my code?

Everything else that doesn't fall into one of the other PB categories.
Killswitch
Enthusiast
Enthusiast
Posts: 731
Joined: Wed Apr 21, 2004 7:12 pm

Bug, or my code?

Post by Killswitch »

Code: Select all


#Pack_Error_CreatePack=-3
#Pack_Error_PackFiles=-4
#Pack_Error_Read=-5
#Pack_Error_CreateDirectory=-6
#Pack_Error_InsallFiles=-7
#Success=1

Structure PackInfo
  DirName.s ;Directories to be created
  FileName.s ;Files to be created
EndStructure

Structure DirectoryInfo
  DirName.s ;Directory Name + Relevent Path
  File.s[2999] ;File names (i.e. bob.txt)
  FileFullName.s[2999] ;Path and directory (i.e. Test\bob.txt)
  Files.l ;No. files in directory
  Dirs.l ;Total No, Sub Directories
  TotalFiles.l ;Total Number of files in all Dirs.
  Path.s
EndStructure

Dim DirInfo.DirectoryInfo(9999)

Dim PackInfo.PackInfo(9999999999)

DirInfo(0)\FileFullName[1]="bob"
DirInfo(0)\FileFullName[2]="bobby"
DirInfo(0)\FileFullName[3]="bobby jim"
DirInfo(0)\Dirs=0
DirInfo(0)\Files=3  
If CreatePack("C:\bob.pak")  
  For t=0 To DirInfo(0)\Dirs
      For x=1 To DirInfo(t)\Files   
        Name.s=DirInfo(t)\FileFullName[x]
        Debug Name
        If Name     
          size=Len(Name)+1
          *filename=AllocateMemory(size)
          PokeS(*filename,Name,size)
          AddPackMemory(*filename,size,9)
          FreeMemory(*filename)
        EndIf
      Next x
    Next t
EndIf
There is some stuff here that does nothing, thats because I reconstructed it out of the entirety of my code. This will crash, however if you change 'size=Len(Name)+1' to 'size=Len(Name)+10' it runs fine.

The length of a string is len()+1 isn't it? So what's going on?
~I see one problem with your reasoning: the fact is thats not a chicken~
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Re: Bug, or my code?

Post by Doobrey »

Since the string is already in memory,replace..

Code: Select all

          size=Len(Name)+1
          *filename=AllocateMemory(size)
          PokeS(*filename,Name,size)
          AddPackMemory(*filename,size,9)
          FreeMemory(*filename)
with..

Code: Select all

        AddPackMemory(@Name,len(Name)+1,9)
Post Reply