diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c2edf6db82..d278a285b7 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,16 @@ 2008-12-31 13:59 UTC+0100 Foo Bar */ +2008-07-08 14:13 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbrddcdx.h + * harbour/source/rdd/dbfcdx/dbfcdx1.c + ! fixed casting for indexes with key length greater then 196 bytes + created on tables with record number smaller then 256. In such + case if keys have equal value then after decoding they may need + more then 32767 bytes and casting to SHORT gives negative indexes. + Thanks to Saulius Zrelskis for example. + % changed some SHORT to INT to reduce runtime overhead + 2008-07-08 10:34 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * contrib/rddads/ads1.c ! Fixed to behave Clipper-like when trying to write diff --git a/harbour/include/hbrddcdx.h b/harbour/include/hbrddcdx.h index 420a22c2e0..4f8db9a4bd 100644 --- a/harbour/include/hbrddcdx.h +++ b/harbour/include/hbrddcdx.h @@ -258,8 +258,8 @@ typedef struct _CDXPAGE ULONG Right; BYTE PageType; - SHORT iKeys; - SHORT iCurKey; + int iKeys; + int iCurKey; BOOL fChanged; BYTE bUsed; @@ -296,7 +296,7 @@ typedef CDXPAGE * LPCDXPAGE; typedef struct _CDXSTACK { LPCDXPAGE Page; - SHORT iKey; + int iKey; } CDXSTACK; typedef CDXSTACK * LPCDXSTACK; diff --git a/harbour/source/rdd/dbfcdx/dbfcdx1.c b/harbour/source/rdd/dbfcdx/dbfcdx1.c index f0311db4c8..dee225aeb3 100644 --- a/harbour/source/rdd/dbfcdx/dbfcdx1.c +++ b/harbour/source/rdd/dbfcdx/dbfcdx1.c @@ -1540,7 +1540,7 @@ static void hb_cdxIndexPoolFree( LPCDXINDEX pIndex, int nPagesLeft ) /* * get key value ptr from index page */ -static BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, SHORT iKey ) +static BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, int iKey ) { #ifdef HB_CDX_DBGCODE if ( iKey < 0 || iKey >= pPage->iKeys ) @@ -1550,7 +1550,7 @@ static BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, SHORT iKey ) return &pPage->pKeyBuf[ iKey * ( pPage->TagParent->uiLen + 6 ) ]; else if ( pPage->PageType & CDX_NODE_LEAF ) { - SHORT iPos, iLen, iTmp, iTrl, iDup; + int iPos, iLen, iTmp, iTrl, iDup; BYTE bTrail; iLen = pPage->TagParent->uiLen; @@ -1596,7 +1596,7 @@ static BYTE * hb_cdxPageGetKeyVal( LPCDXPAGE pPage, SHORT iKey ) /* * get record number from index page */ -static ULONG hb_cdxPageGetKeyRec( LPCDXPAGE pPage, SHORT iKey ) +static ULONG hb_cdxPageGetKeyRec( LPCDXPAGE pPage, int iKey ) { #ifdef HB_CDX_DBGCODE if ( iKey < 0 || iKey >= pPage->iKeys ) @@ -1614,7 +1614,7 @@ static ULONG hb_cdxPageGetKeyRec( LPCDXPAGE pPage, SHORT iKey ) /* * get child page number from interrior index page */ -static ULONG hb_cdxPageGetKeyPage( LPCDXPAGE pPage, SHORT iKey ) +static ULONG hb_cdxPageGetKeyPage( LPCDXPAGE pPage, int iKey ) { #ifdef HB_CDX_DBGCODE if ( iKey < 0 || iKey >= pPage->iKeys ) @@ -1630,7 +1630,7 @@ static ULONG hb_cdxPageGetKeyPage( LPCDXPAGE pPage, SHORT iKey ) /* * get key from uncompressed page */ -static LPCDXKEY hb_cdxPageGetKey( LPCDXPAGE pPage, SHORT iKey, LPCDXKEY pKey ) +static LPCDXKEY hb_cdxPageGetKey( LPCDXPAGE pPage, int iKey, LPCDXKEY pKey ) { return hb_cdxKeyPut( pKey, hb_cdxPageGetKeyVal( pPage, iKey ), @@ -1645,7 +1645,7 @@ static LPCDXKEY hb_cdxPageGetKey( LPCDXPAGE pPage, SHORT iKey, LPCDXKEY pKey ) */ static void hb_cdxPageCheckKeys( LPCDXPAGE pPage ) { - SHORT i, K, iLen = pPage->TagParent->uiLen; + int i, K, iLen = pPage->TagParent->uiLen; ULONG ulRec, ulRecPrev; BYTE * pbVal, pbValPrev[CDX_MAXKEY]; @@ -1679,10 +1679,10 @@ static void hb_cdxPageCheckKeys( LPCDXPAGE pPage ) /* * Check decoded leaf page if all trailing and duplicate characters are set */ -static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, BYTE * pKeyBuf, SHORT iKeys, BOOL fSpc ) +static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys, BOOL fSpc ) { - SHORT iNum = pPage->TagParent->uiLen, iKey, iPos, iFree = CDX_EXT_FREESPACE; - SHORT iLen = iNum + 6; + int iNum = pPage->TagParent->uiLen, iKey, iPos, iFree = CDX_EXT_FREESPACE; + int iLen = iNum + 6; BYTE bDup, bTrl; BYTE bTrail = pPage->TagParent->bTrail; BOOL bErr = FALSE; @@ -1696,9 +1696,9 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, BYTE * pKeyBuf, SHORT iKeys, if ( iKey > 0 ) { #ifdef HB_CDX_PACKTRAIL - SHORT iMax = iNum - bTrl; + int iMax = iNum - bTrl; #else - SHORT iMax = iNum - HB_MAX( pKeyBuf[ iPos - 1 ], bTrl ); + int iMax = iNum - HB_MAX( pKeyBuf[ iPos - 1 ], bTrl ); #endif while ( bDup < iMax && pKeyBuf[ iPos + bDup ] == pKeyBuf[ iPos - iLen + bDup ] ) @@ -1718,7 +1718,7 @@ static void hb_cdxPageCheckDupTrl( LPCDXPAGE pPage, BYTE * pKeyBuf, SHORT iKeys, } if ( iKey > 0 ) { - SHORT K; + int K; K = hb_cdxValCompare( pPage->TagParent, &pKeyBuf[ iPos - iLen ], iNum, &pKeyBuf[ iPos ], iNum, TRUE ); @@ -1790,7 +1790,7 @@ static void hb_cdxSetLeafRecord( BYTE *pDst, ULONG ulRec, int iDup, int iTrl, /* * encode keys in buffer into cdx leaf node */ -static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, BYTE * pKeyBuf, SHORT iKeys ) +static void hb_cdxPageLeafEncode( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys ) { int iKey, iTrl, iDup, iReq, iTmp, iNum, iLen; BYTE *pKeyPos, *pRecPos, *pSrc; @@ -1934,7 +1934,7 @@ static void hb_cdxPageLeafDecode( LPCDXPAGE pPage, BYTE * pKeyBuf ) */ static void hb_cdxPageLeafInitSpace( LPCDXPAGE pPage ) { - SHORT iLen = pPage->TagParent->uiLen; + int iLen = pPage->TagParent->uiLen; BYTE bBits; for ( bBits = 0; iLen; bBits++, iLen >>= 1 ) {} @@ -1950,10 +1950,10 @@ static void hb_cdxPageLeafInitSpace( LPCDXPAGE pPage ) * calculate the size of keys stored in buffer, return * the number of keys wich can be stored in the page */ -static void hb_cdxPageCalcLeafSpace( LPCDXPAGE pPage, BYTE * pKeyBuf, SHORT iKeys ) +static void hb_cdxPageCalcLeafSpace( LPCDXPAGE pPage, BYTE * pKeyBuf, int iKeys ) { - SHORT iNum = pPage->TagParent->uiLen, iKey, iSize; - SHORT iLen = iNum + 6; + int iNum = pPage->TagParent->uiLen, iKey, iSize; + int iLen = iNum + 6; BYTE bDup, bTrl, ReqByte, *bPtr; ULONG ulRec, RNMask; @@ -2008,7 +2008,7 @@ static void hb_cdxPageCalcLeafSpace( LPCDXPAGE pPage, BYTE * pKeyBuf, SHORT iKey */ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) { - SHORT iKey = pPage->iCurKey, iLen = pPage->TagParent->uiLen + 6, iSpc; + int iKey = pPage->iCurKey, iLen = pPage->TagParent->uiLen + 6, iSpc; int iRet = 0; #ifdef HB_CDX_DBGCODE @@ -2035,12 +2035,12 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) pPage->pKeyBuf[ ( iKey + 1 ) * iLen - 1 ]; if ( iKey < pPage->iKeys - 1 ) { - SHORT iPos = ( iKey + 2 ) * iLen - 2, iDup = 0; + int iPos = ( iKey + 2 ) * iLen - 2, iDup = 0; iSpc -= pPage->pKeyBuf[ iPos ]; if ( iKey > 0 ) { - SHORT iPrev = ( iKey - 1 ) * iLen, iNext = ( iKey + 1 ) * iLen, - iNum = pPage->TagParent->uiLen; + int iPrev = ( iKey - 1 ) * iLen, iNext = ( iKey + 1 ) * iLen, + iNum = pPage->TagParent->uiLen; #ifdef HB_CDX_PACKTRAIL iNum -= pPage->pKeyBuf[ iNext + iLen - 1 ]; #else @@ -2104,8 +2104,8 @@ static int hb_cdxPageLeafDelKey( LPCDXPAGE pPage ) */ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) { - SHORT iKey, iNum = pPage->TagParent->uiLen; - SHORT iLen = iNum + 6, iSpc, iTrl, iDup, iMax, iPos; + int iKey, iNum = pPage->TagParent->uiLen; + int iLen = iNum + 6, iSpc, iTrl, iDup, iMax, iPos; BYTE bTrail = pPage->TagParent->bTrail; int iRet = 0; @@ -2217,10 +2217,10 @@ static int hb_cdxPageLeafAddKey( LPCDXPAGE pPage, LPCDXKEY pKey ) /* * set (insert) key in interior node record to (with) given value */ -static void hb_cdxPageIntSetKey( LPCDXPAGE pPage, SHORT iKey, BOOL fIns, BYTE * pbVal, ULONG ulRec, ULONG ulPag ) +static void hb_cdxPageIntSetKey( LPCDXPAGE pPage, int iKey, BOOL fIns, BYTE * pbVal, ULONG ulRec, ULONG ulPag ) { - SHORT iLen = pPage->TagParent->uiLen; - SHORT iPos = iKey * ( iLen + 8 ); + int iLen = pPage->TagParent->uiLen; + int iPos = iKey * ( iLen + 8 ); #ifdef HB_CDX_DSPDBG_INFO printf("\r\nintSetKey (%s): Page=%lx, iKey=%d/%d, ulPag=%lx", @@ -2259,9 +2259,9 @@ static void hb_cdxPageIntSetKey( LPCDXPAGE pPage, SHORT iKey, BOOL fIns, BYTE * /* * delete key in interior node record */ -static void hb_cdxPageIntDelKey( LPCDXPAGE pPage, SHORT iKey ) +static void hb_cdxPageIntDelKey( LPCDXPAGE pPage, int iKey ) { - SHORT iLen = pPage->TagParent->uiLen + 8; + int iLen = pPage->TagParent->uiLen + 8; #ifdef HB_CDX_DSPDBG_INFO printf("\r\nintDelKey: Page=%lx, iKey=%d/%d, ulPag=%lx", @@ -2550,11 +2550,11 @@ static void hb_cdxPageGetChild( LPCDXPAGE pPage ) static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) { LPCDXPAGE childs[ CDX_BALANCE_LEAFPAGES + 2 ], lpTmpPage; - SHORT iChKeys[ CDX_BALANCE_LEAFPAGES + 2 ], - iChFree[ CDX_BALANCE_LEAFPAGES + 2 ]; - SHORT iFirstKey, iBlncKeys = CDX_BALANCE_LEAFPAGES; - SHORT iLen = pPage->TagParent->uiLen + 6, - iKeys = 0, iFree = 0, iSkip = 0, iBufSize = 0; + int iChKeys[ CDX_BALANCE_LEAFPAGES + 2 ], + iChFree[ CDX_BALANCE_LEAFPAGES + 2 ]; + int iFirstKey, iBlncKeys = CDX_BALANCE_LEAFPAGES; + int iLen = pPage->TagParent->uiLen + 6, + iKeys = 0, iFree = 0, iSkip = 0, iBufSize = 0; BYTE * pKeyPool = NULL, * pPtr; BOOL fIns; ULONG ulPage; @@ -2722,7 +2722,7 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) #if 1 if ( !fIns && lpTmpPage != NULL ) { - SHORT j, iSize = 0, iMaxReq; + int j, iSize = 0, iMaxReq; ULONG ulMaxRec = 0, ul; BYTE * pbKey, bMax; @@ -2981,9 +2981,9 @@ static int hb_cdxPageKeyLeafBalance( LPCDXPAGE pPage, int iChildRet ) static int hb_cdxPageKeyIntBalance( LPCDXPAGE pPage, int iChildRet ) { LPCDXPAGE childs[ CDX_BALANCE_INTPAGES + 2 ], lpTmpPage; - SHORT iFirstKey, iBlncKeys = CDX_BALANCE_INTPAGES; - SHORT iLen = pPage->TagParent->uiLen + 8, iKeys = 0, iNeedKeys, iNodeKeys, - iMin = pPage->TagParent->MaxKeys, iMax = 0, iDiv; + int iFirstKey, iBlncKeys = CDX_BALANCE_INTPAGES; + int iLen = pPage->TagParent->uiLen + 8, iKeys = 0, iNeedKeys, iNodeKeys, + iMin = pPage->TagParent->MaxKeys, iMax = 0, iDiv; ULONG ulPage; BYTE * pKeyPool = NULL, *pPtr; BOOL fForce = ( iChildRet & ( NODE_SPLIT | NODE_JOIN ) ) != 0; @@ -3766,7 +3766,7 @@ static int hb_cdxPageSeekKey( LPCDXPAGE pPage, LPCDXKEY pKey, ULONG ulKeyRec, BO if ( fLeaf && !pPage->pKeyBuf && pPage->iKeys > 0 ) { - SHORT iLen = pPage->TagParent->uiLen + 6; + int iLen = pPage->TagParent->uiLen + 6; BYTE *pKeyBuf = (BYTE *) hb_xgrab( pPage->iKeys * iLen ); hb_cdxPageLeafDecode( pPage, pKeyBuf ); pPage->pKeyBuf = pKeyBuf; @@ -4591,7 +4591,7 @@ static void hb_cdxIndexFreePages( LPCDXPAGE pPage ) if ( ( pPage->PageType & CDX_NODE_LEAF ) == 0 ) { LPCDXPAGE pChildPage; - SHORT iKey; + int iKey; for ( iKey = 0; iKey < pPage->iKeys; iKey++ ) { @@ -6014,7 +6014,7 @@ static ERRCODE hb_cdxDBOIKeyGoto( CDXAREAP pArea, LPCDXTAG pTag, ULONG ulKeyNo, } if ( (ULONG) pPage->iKeys >= ulKeyCnt ) { - pPage->iCurKey = pTag->UsrAscend ? ( SHORT ) ulKeyCnt - 1 : pPage->iKeys - ( SHORT ) ulKeyCnt; + pPage->iCurKey = pTag->UsrAscend ? ( int ) ulKeyCnt - 1 : pPage->iKeys - ( int ) ulKeyCnt; hb_cdxSetCurKey( pPage ); } else @@ -6069,7 +6069,7 @@ static BOOL hb_cdxGoToRelKeyPos( LPCDXPAGE pPage, double dPos ) if( pPage->iKeys == 0 ) return FALSE; - pPage->iCurKey = ( SHORT ) ( dPos * pPage->iKeys ); + pPage->iCurKey = ( int ) ( dPos * pPage->iKeys ); if( pPage->iCurKey >= pPage->iKeys ) pPage->iCurKey = pPage->iKeys - 1;