diff --git a/harbour/ChangeLog b/harbour/ChangeLog index bf3c9c2b56..cb1042a5e6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,15 @@ past entries belonging to these authors: Viktor Szakats. */ +2009-05-06 13:14 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/blob.ch + ! fixed minor typo + + * harbour/source/rdd/dbffpt/dbffpt1.c + ! fixed two bugs in garbage collector. One of them was critical and could + cause FPT or DBV file corruption when memoblock size was smaller then 8 + bytes. Thanks to Mike Evans for self contain example. + 2009-05-06 10:50 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * include/hbexprb.c + Allowing user defined 'gettext' functions to be used diff --git a/harbour/include/blob.ch b/harbour/include/blob.ch index 6d546cb0e9..1ce094e3a9 100644 --- a/harbour/include/blob.ch +++ b/harbour/include/blob.ch @@ -54,7 +54,7 @@ #define HB_BLOB_CH_ -#ifndef HB_DBINFO_CH +#ifndef HB_DBINFO_CH_ #include "dbinfo.ch" #endif diff --git a/harbour/source/rdd/dbffpt/dbffpt1.c b/harbour/source/rdd/dbffpt/dbffpt1.c index 8782884eb3..614e3c1602 100644 --- a/harbour/source/rdd/dbffpt/dbffpt1.c +++ b/harbour/source/rdd/dbffpt/dbffpt1.c @@ -492,7 +492,7 @@ static HB_ERRCODE hb_fptPutRootBlock( FPTAREAP pArea, ULONG ulBlock ) static void hb_fptSortGCitems( LPMEMOGCTABLE pGCtable ) { ULONG ulOffset, ulSize; - BOOL fMoved = TRUE; + BOOL fChanged, fMoved = TRUE; int i, j, l; /* this table should be allready quite good sorted so this simple @@ -508,11 +508,14 @@ static void hb_fptSortGCitems( LPMEMOGCTABLE pGCtable ) if( pGCtable->pGCitems[i].ulSize > pGCtable->pGCitems[i+1].ulSize ) { ulOffset = pGCtable->pGCitems[i+1].ulOffset; - ulSize = pGCtable->pGCitems[i+1].ulSize; + ulSize = pGCtable->pGCitems[i+1].ulSize; + fChanged = pGCtable->pGCitems[i+1].fChanged; pGCtable->pGCitems[i+1].ulSize = pGCtable->pGCitems[i].ulSize; pGCtable->pGCitems[i+1].ulOffset = pGCtable->pGCitems[i].ulOffset; + pGCtable->pGCitems[i+1].fChanged = pGCtable->pGCitems[i].fChanged; pGCtable->pGCitems[ i ].ulSize = ulSize; pGCtable->pGCitems[ i ].ulOffset = ulOffset; + pGCtable->pGCitems[ i ].fChanged = fChanged; fMoved = TRUE; pGCtable->bChanged |= 2; l = i; @@ -550,7 +553,8 @@ static void hb_fptPackGCitems( LPMEMOGCTABLE pGCtable ) { if( ulEnd == pGCtable->pGCitems[j].ulOffset ) { - pGCtable->pGCitems[i].ulSize += pGCtable->pGCitems[j].ulSize; + pGCtable->pGCitems[i].ulSize += pGCtable->pGCitems[j].ulSize; + pGCtable->pGCitems[i].fChanged = TRUE; pGCtable->pGCitems[j].ulOffset = pGCtable->pGCitems[j].ulSize = 0; pGCtable->bChanged |= 2; i = -1; @@ -571,6 +575,7 @@ static void hb_fptPackGCitems( LPMEMOGCTABLE pGCtable ) { pGCtable->pGCitems[j].ulOffset = pGCtable->pGCitems[i].ulOffset; pGCtable->pGCitems[j].ulSize = pGCtable->pGCitems[i].ulSize; + pGCtable->pGCitems[j].fChanged = pGCtable->pGCitems[i].fChanged; } j++; } @@ -606,8 +611,15 @@ static HB_ERRCODE hb_fptWriteGCitems( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, US { if( pGCtable->pGCitems[i].fChanged ) { - if( pArea->uiMemoVersion == DB_MEMOVER_FLEX || - pArea->uiMemoVersion == DB_MEMOVER_CLIP ) + if( ( pArea->uiMemoVersion == DB_MEMOVER_FLEX || + pArea->uiMemoVersion == DB_MEMOVER_CLIP ) && + /* TODO: check what FLEX/CL53 exactly does in such situations */ + /* Tests show that FLEX/CL53 does not reuse larger blocks + * which can leave 8 or less dummy bytes so such problem + * does not exists. [druzus] + */ + pGCtable->pGCitems[i].ulSize * pArea->uiMemoBlockSize >= + sizeof( FPTBLOCK ) ) { HB_PUT_BE_UINT32( fptBlock.type, FPTIT_FLEX_UNUSED ); HB_PUT_BE_UINT32( fptBlock.size, pArea->uiMemoBlockSize * @@ -631,7 +643,7 @@ static HB_ERRCODE hb_fptWriteGCitems( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, US * Add new block to GC free memo blocks list. */ static HB_ERRCODE hb_fptGCfreeBlock( FPTAREAP pArea, LPMEMOGCTABLE pGCtable, - ULONG ulOffset, ULONG ulByteSize, BOOL fRaw ) + ULONG ulOffset, ULONG ulByteSize, BOOL fRaw ) { HB_ERRCODE errCode = HB_SUCCESS; ULONG ulSize; @@ -2594,8 +2606,8 @@ static HB_ERRCODE hb_fptReadSMTBlock( FPTAREAP pArea, PHB_ITEM pItem, * Read fpt vartype memos. */ static HB_ERRCODE hb_fptGetMemo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem, - HB_FHANDLE hFile, ULONG ulBlock, ULONG ulStart, - ULONG ulCount ) + HB_FHANDLE hFile, ULONG ulBlock, ULONG ulStart, + ULONG ulCount ) { HB_ERRCODE errCode; ULONG ulSize = 0, ulType = 0; @@ -2821,15 +2833,15 @@ static HB_ERRCODE hb_fptGetMemo( FPTAREAP pArea, USHORT uiIndex, PHB_ITEM pItem, * Write memo data. */ static HB_ERRCODE hb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize, - BYTE *bBufPtr, HB_FHANDLE hFile, - ULONG ulType, ULONG ulLen, ULONG * ulStoredBlock ) + BYTE *bBufPtr, HB_FHANDLE hFile, + ULONG ulType, ULONG ulLen, ULONG * pulStoredBlock ) { MEMOGCTABLE fptGCtable; HB_ERRCODE errCode; BOOL bWrite; HB_TRACE(HB_TR_DEBUG, ("hb_fptWriteMemo(%p, %lu, %lu, %p, %p, %lu, %lu, %p)", - pArea, ulBlock, ulSize, bBufPtr, ( void * ) ( HB_PTRDIFF ) hFile, ulType, ulLen, ulStoredBlock)); + pArea, ulBlock, ulSize, bBufPtr, ( void * ) ( HB_PTRDIFF ) hFile, ulType, ulLen, pulStoredBlock)); bWrite = ( ulLen != 0 || ( pArea->bMemoType == DB_MEMO_FPT && ulType != FPTIT_TEXT && ulType != FPTIT_BINARY && @@ -2837,7 +2849,7 @@ static HB_ERRCODE hb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize, if( ulBlock == 0 && !bWrite ) { - * ulStoredBlock = 0; + *pulStoredBlock = 0; return HB_SUCCESS; } @@ -2864,7 +2876,7 @@ static HB_ERRCODE hb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize, { HB_FOFFSET fOffset; - errCode = hb_fptGCgetFreeBlock( pArea, &fptGCtable, ulStoredBlock, ulLen, + errCode = hb_fptGCgetFreeBlock( pArea, &fptGCtable, pulStoredBlock, ulLen, ulType == FPTIT_DUMMY ); if( errCode != HB_SUCCESS ) { @@ -2872,7 +2884,7 @@ static HB_ERRCODE hb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize, return errCode; } - fOffset = FPT_BLOCK_OFFSET( *ulStoredBlock ); + fOffset = FPT_BLOCK_OFFSET( *pulStoredBlock ); if( pArea->bMemoType == DB_MEMO_FPT && ulType != FPTIT_DUMMY ) { FPTBLOCK fptBlock; @@ -2935,14 +2947,14 @@ static HB_ERRCODE hb_fptWriteMemo( FPTAREAP pArea, ULONG ulBlock, ULONG ulSize, ULONG ulBlocks = ( ulLen + sizeof( FPTBLOCK ) + pArea->uiMemoBlockSize - 1 ) / pArea->uiMemoBlockSize; hb_fileWriteAt( pArea->pMemoFile, ( BYTE * ) "\xAF", 1, - FPT_BLOCK_OFFSET( *ulStoredBlock + ulBlocks ) - 1 ); + FPT_BLOCK_OFFSET( *pulStoredBlock + ulBlocks ) - 1 ); } } pArea->fMemoFlush = TRUE; } else { - * ulStoredBlock = 0; + *pulStoredBlock = 0; } if( errCode == HB_SUCCESS )