"Wilson, Mike E." <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I have a repeat button that performs a decrement on a year that works fine the first time through. The second, third or fourth time I hit the repeat button it gets the following error message: > > Writer's Edge (1.0) just read from memory location 0x0003BF49, which is in Memory Manager data structures. > > These data structures include things like the headers preceding each block in a heap, as well as the heap header itself. Such an access usually means that an application allocated a buffer (possibly with MemPtrNew) that wasn't large enough for its purpose. When the application then tries to write data to the buffer, it writes off the end of the buffer, accessing the start of the buffer following it in memory. > > It can happen on the second, maybe on the fourth time. Here is the code for the procedure: > > static Boolean frmCalendar_rptYearDec_OnSelect(EventPtr event) > { > // Insert code for rptYearDec > int bufint; > FormPtr form = FrmGetActiveForm(); > FieldPtr fld = (FieldPtr)FrmGetObjectPtr(form, FrmGetObjectIndex(form, fldYear)); > > UInt16 len = FldGetTextLength(fld); > Char* buf = (Char*)MemPtrNew(len+1); > StrNCopy(buf, FldGetTextPtr(fld), len); > bufint = StrAToI(buf); > bufint = bufint - 1; > StrCopy(buf,StrIToA(buf,bufint)); > FldDelete(fld,0,20); > FldInsert(fld, buf, len); > MemPtrFree(buf); > return true; > } > > Appreciate any help! > > Michael W >
You aren't copying the null terminator to your buffer, use StrCopy instead of StrNCopy or increase the StrNCopy length by 1 or ensure that the buffer contains terminator before calling StrNCopy. Your buffer is already the exact size required so no need for StrNCopy. Also what is "StrCopy(buf,StrIToA(buf,bufint))" about? Why not just StrIToA(buf,bufint)? Ralph -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
