ppcdev
2003-11-26 10:48:18 UTC
Hi. I'm programming a generic application to convert a TXT file to a
PDB file on the PalmOS. Here are the pieces of source code that make
me so nervous ; ) :
Platform : Tungsten C
IDE : CodeWarrior R9
OS : PalmOS 5
// pieces of source code from conduit.dsw (in OpenConduit)
...
#pragma pack(2) //DOESNT WORK WITH #PRAGMA PACK(4)?ARM alignment!=68K
alignment?
struct Packed_Record
{
long u_id;
char name[1];
};
#pragma pack()
...
long unique_id = atol(szTab[0]);
memset(gBigBuffer,0,sizeof(gBigBuffer));
Packed_Record *cp = (Packed_Record *) gBigBuffer;
cp->u_id = SyncHostToHHDWord(unique_id);
char *s = cp->name;
for(int j=1;j<(nbfields-1);j++)
{
memcpy(s, szTab[j], strlen(szTab[j]));
s += strlen(szTab[j]) + 1;
}
int iLenPacked_Record; iLenPacked_Record = s - (char *) gBigBuffer;
CRawRecordInfo recordInfo;
memset( &recordInfo, 0, sizeof(recordInfo) ) ;
recordInfo.m_FileHandle = hDataBase;
recordInfo.m_Attribs = 0;
recordInfo.m_CatId = 0;
recordInfo.m_RecId = 0;
recordInfo.m_RecIndex = 0;
recordInfo.m_pBytes = (unsigned char *) gBigBuffer;
recordInfo.m_TotalBytes = iLenPacked_Record;
recordInfo.m_RecSize = iLenPacked_Record;
recordInfo.m_dwReserved = 0;
long err = SyncWriteRec(recordInfo);
...
// the return code is always OK. but data on the HH are truncated...
// piece of source code on the palmos (codewarrior r9)
...
typedef struct
{
long id_record;
char *p_nom;
char *p_prenom;
char *p_motdepasse;
} Record;
Record* record;
typedef struct
{
long unique_id;
char name[1];
} PackedRecord;
PackedRecord* gRecPointer;
MemHandle gRecHandle;
...
int iRecIndex=0;
gRecPointer=(PackedRecord*) MemPtrNew(256);
gRecHandle = DmGetRecord(db, iRecIndex);
if (gRecHandle==NULL)
{
FrmCustomAlert(InfoAlert,"erreur gRecHandle=NULL"," "," ");
return;
}
gRecPointer = (PackedRecord*) MemHandleLock(gRecHandle);
record=(Record*)MemPtrNew(256);
record->id_record = gRecPointer->unique_id;
char sztest[24]; StrIToA(sztest, record->id_record);
FrmCustomAlert(InfoAlert, sztest, sztest, sztest);
char* s=(char*) MemPtrNew(1024);
s=gRecPointer->name;
record->p_nom=s;
char* sz1=record->p_nom;
MemPtrFree(s);
FrmCustomAlert(InfoAlert,sz1,sz1,sz1);
DmReleaseRecord(gPdbHandle, iRecIndex, true);
MemHandleUnlock(gRecHandle);
...
// END OF ALL THAT STUFF
It is assumed that szTab[] is an array of string that I parse from a
TXT or CSV file. I've verified the data (by writtin in the log files)
and they are all ok.
The record creation from the conduit is also OK. The PDB is well
created, but the data inside are truncated ? I thought of a gBigBuffer
size problem ? But it doesnt seem to be that... I think the problem is
in the packing area... in the following part :
for(int j=1;j<(nbfields-1);j++)
{
memcpy(s, szTab[j], strlen(szTab[j]));
s += strlen(szTab[j]) + 1;
}
Do you think the same?
That source code really drives me crazy ! Any help would be great
!!!!!
Thanks
PDB file on the PalmOS. Here are the pieces of source code that make
me so nervous ; ) :
Platform : Tungsten C
IDE : CodeWarrior R9
OS : PalmOS 5
// pieces of source code from conduit.dsw (in OpenConduit)
...
#pragma pack(2) //DOESNT WORK WITH #PRAGMA PACK(4)?ARM alignment!=68K
alignment?
struct Packed_Record
{
long u_id;
char name[1];
};
#pragma pack()
...
long unique_id = atol(szTab[0]);
memset(gBigBuffer,0,sizeof(gBigBuffer));
Packed_Record *cp = (Packed_Record *) gBigBuffer;
cp->u_id = SyncHostToHHDWord(unique_id);
char *s = cp->name;
for(int j=1;j<(nbfields-1);j++)
{
memcpy(s, szTab[j], strlen(szTab[j]));
s += strlen(szTab[j]) + 1;
}
int iLenPacked_Record; iLenPacked_Record = s - (char *) gBigBuffer;
CRawRecordInfo recordInfo;
memset( &recordInfo, 0, sizeof(recordInfo) ) ;
recordInfo.m_FileHandle = hDataBase;
recordInfo.m_Attribs = 0;
recordInfo.m_CatId = 0;
recordInfo.m_RecId = 0;
recordInfo.m_RecIndex = 0;
recordInfo.m_pBytes = (unsigned char *) gBigBuffer;
recordInfo.m_TotalBytes = iLenPacked_Record;
recordInfo.m_RecSize = iLenPacked_Record;
recordInfo.m_dwReserved = 0;
long err = SyncWriteRec(recordInfo);
...
// the return code is always OK. but data on the HH are truncated...
// piece of source code on the palmos (codewarrior r9)
...
typedef struct
{
long id_record;
char *p_nom;
char *p_prenom;
char *p_motdepasse;
} Record;
Record* record;
typedef struct
{
long unique_id;
char name[1];
} PackedRecord;
PackedRecord* gRecPointer;
MemHandle gRecHandle;
...
int iRecIndex=0;
gRecPointer=(PackedRecord*) MemPtrNew(256);
gRecHandle = DmGetRecord(db, iRecIndex);
if (gRecHandle==NULL)
{
FrmCustomAlert(InfoAlert,"erreur gRecHandle=NULL"," "," ");
return;
}
gRecPointer = (PackedRecord*) MemHandleLock(gRecHandle);
record=(Record*)MemPtrNew(256);
record->id_record = gRecPointer->unique_id;
char sztest[24]; StrIToA(sztest, record->id_record);
FrmCustomAlert(InfoAlert, sztest, sztest, sztest);
char* s=(char*) MemPtrNew(1024);
s=gRecPointer->name;
record->p_nom=s;
char* sz1=record->p_nom;
MemPtrFree(s);
FrmCustomAlert(InfoAlert,sz1,sz1,sz1);
DmReleaseRecord(gPdbHandle, iRecIndex, true);
MemHandleUnlock(gRecHandle);
...
// END OF ALL THAT STUFF
It is assumed that szTab[] is an array of string that I parse from a
TXT or CSV file. I've verified the data (by writtin in the log files)
and they are all ok.
The record creation from the conduit is also OK. The PDB is well
created, but the data inside are truncated ? I thought of a gBigBuffer
size problem ? But it doesnt seem to be that... I think the problem is
in the packing area... in the following part :
for(int j=1;j<(nbfields-1);j++)
{
memcpy(s, szTab[j], strlen(szTab[j]));
s += strlen(szTab[j]) + 1;
}
Do you think the same?
That source code really drives me crazy ! Any help would be great
!!!!!
Thanks