> >/***********************************************************************
> > *
> > * FUNCTION:    UnpackInfo()
> > *
> > * DESCRIPTION: This routine unpacks a packed Info structure
> > *
> > * PARAMETERS: info - Pointer to a Info structure
> > *    packedInfo - Pointer to a packed Info structure
> > *
> > * RETURNED:    void
> > *
> > ***********************************************************************/
> >void UnpackInfo(tblInfoPtr info, const tblPackedInfoPtr packedInfo)
> >{
> >     const char *s = packedInfo->Strings;
> >     info->UnitType = packedInfo->UnitType;
> >     info->Beginning = packedInfo->Beginning;
> >     info->Ending = packedInfo->Ending;
> >     info->Number = packedInfo->Number;
> >     info->TNumber = s;
>
> Bad boy!  You are having the char * field TNumber point
> directly into the packedInfo memory.  Assuming that packedInfo
> is a temporary thing used only while unpacking you will end
> up with nothing very shortly.  What you need to do is to -copy-
> that information.  Try this:
>
>     info->TNumber = MemPtrNew(StrLen(s)+1);
>     StrCopy(info->TNumber, s);
>
> ... same goes for all of the following strings.


If he is following the O'Reilly book example, which I think he is,
then this is how the book does it.  The book does warn that you
must keep packedInfo around or else the unpackedInfo becomes
invalid.  Saves on memory and clock cycles if you can keep that
straight.

>
>
> >     s += StrLen(s) + 1;
> >     info->TNumber2 = s;
> >     s += StrLen(s) + 1;
> >     info->Driver = s;
> >     s += StrLen(s) + 1;
> >     info->StartDate = s;
> >     s += StrLen(s) + 1;
> >     info->EndDate = s;
> >     s += StrLen(s) + 1;
> >     info->Origin = s;
> >     s += StrLen(s) + 1;
> >     info->Destination = s;
> >     s += StrLen(s) + 1;
> >}
> >
> >
>
> --
> -Richard M. Hartman
> [EMAIL PROTECTED]
>
> 186,000 mi/sec: not just a good idea, it's the LAW!
>
>
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html
>
>


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to