I'm a little concerned about that
    length += StrLen(rec->Data[index]);

I -assume- that DmStrCopy() will write a terminating NUL char, which
means that your length should be StrLen(rec->Data[index])+1;  Right
now the memhandle you are allocating will be short by one byte per
string.


--
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi/sec: not just a good idea, it's the LAW!


[EMAIL PROTECTED] wrote in message <25912@palm-dev-forum>...
>
>
>
>Hi All,
>
>I have problem understanding why data in rec gets changed in following
function.
>What it does is simple, write data from record rec to the record handle
recordH.
>While doing DmStrCopy, some data in the record gets changed.  I don't
understand
>why.  I am not sure if this was caused by the available dynamic memory.
Thank
>you in advance.
>
>
>void PackFrpFacility(FrpFacility* rec, MemHandle recordH)
>{
>     UInt16 length = 0;
>     char*     s;
>     UInt16    strLen = 0;
>     UInt16 index;
>
>     length = sizeof(rec->frp_id) + sizeof(rec->frp_facility_id);
>     for (index = 0; index < frp_facilityCount; index++)
>          length += StrLen(rec->Data[index]);
>     length += frp_facilityCount;  file://number of string fields
>     if (MemHandleResize(recordH, length) == 0)    {
>          s = MemHandleLock(recordH);
>          DmWrite(s, OffsetOf(FrpFacilityPacked, frp_id), (char*)
&rec->frp_id,
>sizeof(rec->frp_id) );
>          DmWrite(s, OffsetOf(FrpFacilityPacked, frp_facility_id), (char*)
>&rec->frp_facility_id, sizeof(rec->frp_facility_id) );
>          for (index = 0; index < frp_facilityCount; index++)     {
>               DmStrCopy(s, OffsetOf(FrpFacilityPacked, Data) + strLen,
>rec->Data[index]);
>               strLen += StrLen(rec->Data[index]) + 1;
>          }
>          MemHandleUnlock(recordH);
>     }
>}
>
>
>
>
>



-- 
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