This code will always fail if msg has more than 9 characters. You are
asking StrNCopy to copy up to 17 characters into a memory location with only
room for 9 plus the terminating '\0'. You need to allocate room for 18
characters (e.g. Y[18] and/or MemHandleNew(18)) and must also remember that
if msg is longer than 17 characters StrNCopy will not supply the terminator.
Regards, Nick
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Saturday, 5 February 2000 7:59
To: Palm Developer Forum
Subject: RE: CharPtr X and char X[10] difference?
Thank you for your response. An error occured in my program, it seems
that too much dynamic
memory is used, PALM OS crashed.
The code is similar with following your example:
static void MyFunc(CharPtr msg)
{
CharPtr X;
Char Y[10];
VoidHand MsgHandle;
MsgHandle =MemHandleNew(10);
X=MemHandleLock(MsgHandle);
StrNCopy(X, msg, 17); // ERROR. No memory to hold msg contents
StrNCopy(Y, msg, 17); // OK if msg has less than 10 chars
....
MemHandleUnlock(recordH);
MemHandleFree(MsgHandle);
}
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html