April 26, 2024, 08:02:25 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Unicode Heap Problems

Started by Zen, December 22, 2006, 03:20:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

Why is this code causing my program to crash at runtime?

FreeHeap(m_string);

m_string = AllocHeap(len(str) + 1);

*(wstring)m_string = str;


Note: I have m_string declared as heap.

Lewis

Zen

Hmmmm Ive just debuged it and if i put a break point just before that method. This appears in the debug context...

Starting debug session...
Loading DLL: ntdll.dll
Loading DLL: C:\WINDOWS\system32\kernel32.dll
Loading DLL: C:\WINDOWS\system32\USER32.DLL
Loading DLL: C:\WINDOWS\system32\GDI32.dll
Loading DLL: C:\WINDOWS\system32\IMM32.DLL
Loading DLL: C:\WINDOWS\system32\ADVAPI32.dll
Loading DLL: C:\WINDOWS\system32\RPCRT4.dll
Loading DLL: C:\WINDOWS\system32\LPK.DLL
Loading DLL: C:\WINDOWS\system32\USP10.dll
Loading DLL: C:\WINDOWS\system32\msvcrt.dll
User breakpoint encountered: Address 0x00404087
HEAP[CString.exe]:
Invalid Address specified to RtlFreeHeap( 00860000, 0012FFB8 )
User breakpoint encountered: Address 0x7C901230


It was the invalid address specified for RtlFreeHeap that caught my eye. Does this mean anything?

Lewis

Mike Stefanik

If you allocate memory for a Unicode string, you need to allocate at least 2 * (length + 1) bytes. Remember, each character is 2 bytes (at least; with UTF-32, each character is 4 bytes).
Mike Stefanik
www.catalyst.com
Catalyst Development Corporation

Ionic Wind Support Team

Yep.  Aurora uses UTF-16 so the *2 is important.
Ionic Wind Support Team