PB 5.21 FreeMemory() error

Just starting out? Need help? Post your questions and find answers here.
troy
User
User
Posts: 51
Joined: Sat May 31, 2003 2:59 pm

PB 5.21 FreeMemory() error

Post by troy »

Hi, getting ima error on FreeMemory(*buffer) in this piece of code:

Code: Select all

str.s = "0123456789012345678901234567890123456789"

size.l = StringByteLength(str, #PB_UTF8)
*buffer = AllocateMemory(size)
If *buffer
    
  PokeS(*buffer, str, size, #PB_UTF8)
  str = MD5Fingerprint(*buffer, size)
  Debug str
  FreeMemory(*buffer) <--- IMA error
      
EndIf
Faced with the error only if I had Len(str) = 40. Is this bug on not?

Win 7, PB 5.21 x86
--
troy
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PB 5.21 FreeMemory() error

Post by luis »

No, the bug is in front of the monitor :)

Read PokeS() help, or enable purifier, or do both :wink:

HINT: null
Is this bug on not?
Then why aren't you posting this in coding question :?:
Last edited by luis on Wed Mar 05, 2014 6:04 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: PB 5.21 FreeMemory() error

Post by STARGÅTE »

PokeS() write an additional NUL-character at the end.

So you have to allocate size+1:

Code: Select all

size.l = StringByteLength(str, #PB_UTF8)
*buffer = AllocateMemory(size+1)
If *buffer
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Alex777
User
User
Posts: 49
Joined: Sun Nov 16, 2008 12:47 am
Location: Cayman Is.
Contact:

Re: PB 5.21 FreeMemory() error

Post by Alex777 »

luis wrote:No, the bug is in front of the monitor :)
:lol:
Post Reply