(Solved) short program dies on AllocateMemory (5.73 x64)

Just starting out? Need help? Post your questions and find answers here.
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

(Solved) short program dies on AllocateMemory (5.73 x64)

Post by Cyllceaux »

Code: Select all

EnableExplicit

Define text1.s=~"Hällo Welt #@€ß\nHöLLo Würldz"
Define size=StringByteLength(text1)
Define *mem=AllocateMemory(size)
CopyMemoryString(text1,@*mem):*mem-size		
Define *res1=AllocateMemory(size) ; Here it dies

Win10 x64 21H1
Last edited by Cyllceaux on Wed Jul 28, 2021 6:06 am, edited 1 time in total.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: short program dies on AllocateMemory (5.73 x64)

Post by GPI »

I can't test it here, but the *mem-Buffer is to small, StringByteLength return the length without the zero-end-byte, CopyMemoryString DOES copy the zero-byte. You should add a "SizeOf(Character)".
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: short program dies on AllocateMemory (5.73 x64)

Post by wilbert »

GPI is right.
You have to allocate room for one additional character.

Code: Select all

Define *mem=AllocateMemory(size + SizeOf(Character))
Windows (x64)
Raspberry Pi OS (Arm64)
Cyllceaux
Enthusiast
Enthusiast
Posts: 458
Joined: Mon Jun 23, 2014 1:18 pm
Contact:

(Solved) Re: short program dies on AllocateMemory (5.73 x64)

Post by Cyllceaux »

OOOOOHHH.... I forgot...

Thx GPI and wilbert :)
Post Reply