Anders,

>"AppName" 1.0 has just written directly to memory manager data structures.

That error message generally indicates that you overwrote a buffer.  That is,
you allocated a buffer of a certain size, and then tried to copy more data into
it than would fit.

>   currentTransInfo->user = (VoidHand)MemHandleNew(sizeof(textPtr));

You're allocating a 4-byte buffer here.  That's the size of textPtr.  When you
copy a long string into a 4-byte buffer, you're going to overflow the buffer.

Try the following instead:

   currentTransInfo->user = MemHandleNew(StrLen(textPtr) + 1);

-- Keith Rollin
-- Palm OS Emulator engineer






Anders Larsson <[EMAIL PROTECTED]> on 11/27/2000 10:34:22 AM

Please respond to "Palm Developer Forum" <[EMAIL PROTECTED]>

Sent by:  Anders Larsson <[EMAIL PROTECTED]>


To:   "Palm Developer Forum" <[EMAIL PROTECTED]>
cc:    (Keith Rollin/US/PALM)
Subject:  written to memory manager structure



Hello all,

I use a struct, see below, to store information. But I cannot copy data
to it by using dynamic memory allocation. It's no problem if I use
static memory allocation.
Please see my code snippet below and see what is wrong.
I would really appreciate if someone could help me.

-------------------------------------------------------------------
// Define a struct
typedef struct TransInfo
{
    VoidHand user;
    VoidHand password;
 } TransInfo;

// Declare a struct pointer
 TransInfo* currentTransInfo;

 VoidHand  textHandle;
 CharPtr  textPtr;
 FieldPtr  fldptrid;

   // Get data from textfield
   fldptrid = (FieldPtr) GetObjectPtr(UseridEditField);
   textHandle = FldGetTextHandle(fldptrid);
   textPtr = (CharPtr)MemHandleLock(textHandle);

   // Get handle to a string in the struct
   currentTransInfo->user = (VoidHand)MemHandleNew(sizeof(textPtr));
   loginPtr = (CharPtr)MemHandleLock(currentTransInfo->user);
   // Copy the data from the record to the new memory chunk.
   StrCopy(loginPtr, textPtr);
-------------------------------------------------------------------

The last statement, "StrCopy(loginPtr, textPtr);" , generates following
error message when I debug:
------------------------------------------------------------------------------

"AppName" 1.0 has just written directly to memory manager data
structures.
This problem indicates an error in the application...etc.
-----------------------------------------------------------------------------

Can anyone tell me, why is that?

Regards, Anders





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to