I am trying to assign two pointers to the same character in two different 
strings.  If I assign the pointers once, they seem to work.  If I attempt to 
reassign the pointers to another location in the same character strings, I get 
an error.  One of the strings is a char * passed to the function.  The other is 
a pointer to a record structure.  

The error is (in abbreviated terms):

"wrote to memory location in the stoarge heap.  Use special functions calls to 
access this area."

The problem seems to be caused if I assign the char pointers "try1" and "try2" 
to another location in the same strings.  It doesn't happen with the first 
assignment.


The code that causes the problem looks like:

Err ClosestSort(Char* Text, DmOpenRef dbase)
{
int i,j,MinLength,matchnum=0, Test;
TransStruct* Record = (TransStruct *) MemPtrNew(sizeof(TransStruct));
char* try1;
char* try2,try3;
char tryit;
Err err = 0;
MemHandle h;

        for(i = 0;i<DmNumRecords(dbase);i++)
        {
        h = DmGetRecord(dbase, i);
        if (h) 
                { 
                
                // could fail due to out of memory!  check to see if you've got 
the handle
                TransStructType * p = (TransStructType *) MemHandleLock(h);
                //preceding line associated the transstruct structure with the
                //memory chunk associated with the record that has been 
associated
                //with a handle
                if (StrLen(Text) < StrLen(p->TrName))
                {
                MinLength = StrLen(Text);
                }
                else
                {
                MinLength = StrLen(p->TrName);
                }
                
                
                if (MinLength>0)
                {       
                *try1=p->TrName[0];
                
                *try2=Text[0];
                Test= TxtCaselessCompare (try1,1, NULL, try2,1, NULL); 
                }

//PROBLEM OCCURS IF I ADD THE FOLLOWING "IF" STATEMENT:
                if (MinLength>1)
                {       
                *try1=p->TrName[0];
                
                *try2=Text[0];
                Test= TxtCaselessCompare (try1,1, NULL, try2,1, NULL); 
                }
                
                
                matchnum = Test;
                Record->DegreeMatch=matchnum;
                
                err = DmWrite(p, OffsetOf(TransStructType, 
DegreeMatch),&Record->DegreeMatch, sizeof(Record->DegreeMatch));             
                
                
                MemPtrUnlock(p);
                DmReleaseRecord(dbase, i, true);
                matchnum=0;
                }
        }
return err;
}

Thanks for any assistance with this.
-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to