I'm going nuts. I can't see what is wrong here, but when I call MemMove from
a subFunction, the stack disappears in the debugger and when control returns
to the calling function (saveWSTCell), MemMove calls say I have just written
to an unallocated chunk of memory. If I comment the MemMove out of the
subFunction, the calling function is no longer messed up.
If anyone can help me out, it'd save me pulling out a lot more hair.
Thanks. -Stan.
static Boolean saveWSTCell( VoidPtr table, Word row, Word column )
{
/* some irrelevant lines */
if ( field && FldDirty( field ) )
{
VoidHand h = gHandles[(set - 1)][record];
CharPtr s;
int i;
CharPtr precord;
Int offset;
Char dummyString[ DB_SET_STRING_SIZE ];
Int numSets;
// Store string in database
hrecord = DmGetRecord( reflexDB, record );
precord = MemHandleLock( hrecord );
offset = subFunction( column, record ); // offset gets correct value (86)
DmWrite( precord, offset, s, StrLen( s ) + 1 );
MemHandleUnlock( hrecord );
DmReleaseRecord( reflexDB, record, true );
// Just to see what it put in the record
offset = subFunction( column, record );
hrecord = DmQueryRecord( reflexDB, record );
precord = MemHandleLock( hrecord );
/* FAILS here -- writing to unallocated memory!? */
MemMove( &dummyString, precord + offset, DB_SET_STRING_SIZE );
MemHandleUnlock( hrecord );
TblMarkRowInvalid( table, row );
result = true;
}
return result;
}
// Takes a column and record and returns appropriate DB offset
static Int subFunction( Word column, Int record )
{
Int numSets;
CharPtr precord;
Char dummyString[ DB_SET_STRING_SIZE ];
hrecord = DmQueryRecord( reflexDB, record );
precord = MemHandleLock( hrecord );
/* If I comment out this next MemMove line, the stack does not disappear and
the callingFunction is not messed up.*/
MemMove( &numSets, precord + DB_NUM_SETS_START, DB_NUM_SETS_SIZE );
MemHandleUnlock( hrecord );
return 86; // For debugging purposes, I hard-coded the correct value to
return.
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/