diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 883aeff888..4bda4e07df 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,10 @@ +2001-09-13 06:02 UTC+0100 Viktor Szakats + + * source/vm/arrays.c + ! hb_arraySize() fixed. Now it will do nothing if the passed size + equals with the size of passed array. Caused mem. alloc. error + with empty arrays. Reported by Brian Hays. + 2001-09-11 10:37 GMT Dave Pearson * source/rtl/profiler.prg * Renamed classes from HB_* to HB*. diff --git a/harbour/source/vm/arrays.c b/harbour/source/vm/arrays.c index 6fb7c7f2a3..9381e5dc45 100644 --- a/harbour/source/vm/arrays.c +++ b/harbour/source/vm/arrays.c @@ -152,43 +152,47 @@ BOOL hb_arraySize( PHB_ITEM pArray, ULONG ulLen ) if( HB_IS_ARRAY( pArray ) ) { PHB_BASEARRAY pBaseArray = pArray->item.asArray.value; - ULONG ulPos; - if( ! pBaseArray->ulLen ) + if( ulLen != pBaseArray->ulLen ) { - pBaseArray->pItems = ( PHB_ITEM ) hb_xgrab( ulLen * sizeof( HB_ITEM ) ); + ULONG ulPos; - for( ulPos = 0; ulPos < ulLen; ulPos++ ) - ( pBaseArray->pItems + ulPos )->type = HB_IT_NIL; - } - else - { - if( pBaseArray->ulLen < ulLen ) + if( pBaseArray->ulLen == 0 ) { - pBaseArray->pItems = ( PHB_ITEM ) hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); - - /* set value for new items */ - for( ulPos = pBaseArray->ulLen; ulPos < ulLen; ulPos++ ) + pBaseArray->pItems = ( PHB_ITEM ) hb_xgrab( ulLen * sizeof( HB_ITEM ) ); + + for( ulPos = 0; ulPos < ulLen; ulPos++ ) ( pBaseArray->pItems + ulPos )->type = HB_IT_NIL; } - else if( pBaseArray->ulLen > ulLen ) + else { - /* release old items */ - for( ulPos = ulLen; ulPos < pBaseArray->ulLen; ulPos++ ) - hb_itemClear( pBaseArray->pItems + ulPos ); - - if( ulLen == 0 ) + if( pBaseArray->ulLen < ulLen ) { - hb_xfree( pBaseArray->pItems ); - pBaseArray->pItems = NULL; - } - else pBaseArray->pItems = ( PHB_ITEM ) hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); + + /* set value for new items */ + for( ulPos = pBaseArray->ulLen; ulPos < ulLen; ulPos++ ) + ( pBaseArray->pItems + ulPos )->type = HB_IT_NIL; + } + else if( pBaseArray->ulLen > ulLen ) + { + /* release old items */ + for( ulPos = ulLen; ulPos < pBaseArray->ulLen; ulPos++ ) + hb_itemClear( pBaseArray->pItems + ulPos ); + + if( ulLen == 0 ) + { + hb_xfree( pBaseArray->pItems ); + pBaseArray->pItems = NULL; + } + else + pBaseArray->pItems = ( PHB_ITEM ) hb_xrealloc( pBaseArray->pItems, sizeof( HB_ITEM ) * ulLen ); + } } + + pBaseArray->ulLen = ulLen; } - pBaseArray->ulLen = ulLen; - return TRUE; } else