From e954231699a5183b307dc8c8d2efaad92de650b4 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Thu, 19 Aug 1999 10:49:00 +0000 Subject: [PATCH] 19990819-12:30 GMT+1 --- harbour/ChangeLog | 5 +++++ harbour/source/rtl/strings.c | 38 ++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e0c84928e3..bef86aa993 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +19990819-12:30 GMT+1 Victor Szel + * source/rtl/strings.c + ! hb_itemStr() possible error fixed when item.asDouble was + accessed without making sure whether the item is a double. + 19990819-00:15 EDT Paul Tucker * source/rtl/gtapi.c + hb_gtPreExt() diff --git a/harbour/source/rtl/strings.c b/harbour/source/rtl/strings.c index e0b59f7539..99d60b9fb4 100644 --- a/harbour/source/rtl/strings.c +++ b/harbour/source/rtl/strings.c @@ -1234,14 +1234,36 @@ HARBOUR HB_VAL( void ) /* TODO: Move it to itemapi.c */ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) { - char * szResult = 0; + char * szResult = NULL; if( pNumber ) { /* Default to the width and number of decimals specified by the item, with a limit of 20 integer places and 9 decimal places */ - int iWidth = pNumber->item.asDouble.length; - int iDec = pNumber->item.asDouble.decimal; + int iWidth; + int iDec; + + if ( IS_DOUBLE( pNumber ) ) + { + iWidth = pNumber->item.asDouble.length; + iDec = pNumber->item.asDouble.decimal; + } + else if ( IS_INTEGER( pNumber ) ) + { + iWidth = pNumber->item.asInteger.length; + iDec = 0; + } + else if ( IS_LONG( pNumber ) ) + { + iWidth = pNumber->item.asLong.length; + iDec = 0; + } + else + { + iWidth = 0; + iDec = 0; + } + if( iWidth > 20 ) iWidth = 20; if( iDec > 9 ) @@ -1301,14 +1323,14 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) } else switch( pNumber->type & ~IT_BYREF ) { - case IT_LONG: - iBytes = sprintf( szResult, "%*li", iWidth, pNumber->item.asLong.value ); - break; - case IT_INTEGER: iBytes = sprintf( szResult, "%*i", iWidth, pNumber->item.asInteger.value ); break; + case IT_LONG: + iBytes = sprintf( szResult, "%*li", iWidth, pNumber->item.asLong.value ); + break; + default: iBytes = 0; *szResult = 0; @@ -1318,7 +1340,7 @@ char * hb_itemStr( PHB_ITEM pNumber, PHB_ITEM pWidth, PHB_ITEM pDec ) if( iBytes > iSize ) { memset( szResult, '*', iSize ); - szResult[ iSize ] = 0; + szResult[ iSize ] = '\0'; } } }